Winston: Error objects are not logged

Created on 3 Aug 2018  路  6Comments  路  Source: winstonjs/winston

Please tell us about your environment:

  • _winston version?_

    • [ ] winston@2

    • [X] winston@3

  • _node -v outputs:_ v9.5.0
  • _Operating System?_ macOS
  • _Language?_ ES6/7

What is the problem?

The following code does not log the Error object, but just:

{"level":"error","message":{},"timestamp":"2018-08-03T13:38:21.376Z"}
const winston = require('winston');

const logger = winston.createLogger({
  level: 'info',
  transports: [
    new winston.transports.Console({
      format: winston.format.combine(winston.format.timestamp(), winston.format.json())
    })
  ]
});

logger.log({ level: 'error', message: new Error("Yo, it's on fire") });

I experimented with custom formatters:

winston.format.printf(info => `${info.timestamp} [ ${info.level} ] ${info.message}`)

which logs the Error message, but there's still no stack trace.

What do you expect to happen instead?

Coming from Winston@2, I'd expect this to log the Error object including a stack trace.

All 6 comments

I have the same problem. I use winston-mongodb, and in 'meta' property in database I see level and error message, but not error object.

+1

Same problem here.

Error object gives undefined

still not fixed :confused:

Valid concerns! There is a nice workaround by @SamuelMaddox17 / @indexzero in #1338 , but we should do something so this works more out-of-the-box. Let's track this issue in #1338 since it's the same thing. Thanks all!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anks333 picture anks333  路  3Comments

sinai-doron picture sinai-doron  路  3Comments

mohanen picture mohanen  路  4Comments

Infinitay picture Infinitay  路  3Comments

Buzut picture Buzut  路  3Comments