Logging error on winston update must be an object with a log method

I noticed when doing the section I had an error and server crash “Invalid transport, must be an object with a log method”

so I check documentation and there is only one reference to log method which says something about and needing to call createLogger()

HOWEVER!! after much testing and comparison between i realized winston.transport’s File is a constructor function and needs to bee newed up before and becomes a function where you pass a transport object so this fixed the issue.

working solution

winston.add(new winston.transports.File({ filename: “logfile.log”}))

mosh’s implementation now deprecated

winston.add(winston.transports.File, { filename: “logfile.log”})

Figured out timestamp is not automatically set, this is the new implementation.

winston.add(new winston.transports.File({ filename: “logfile.log”,
format: winston.format.combine(
winston.format.timestamp(), // Add timestamp to logs
winston.format.json())}))