question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error objects are not logged

See original GitHub issue

Please tell us about your environment:

  • winston version?
    • winston@2
    • 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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
hbakhtiyorcommented, Aug 26, 2018

still not fixed 😕

0reactions
DABHcommented, Sep 3, 2018

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Winston not displaying error details - node.js - Stack Overflow
A quick and dirty way would be to log err.stack : logger.error(err.stack); ... Just addded a layer above Winston to handle error objects....
Read more >
[3.0.0] Error object is not parsed or printed #1338 - GitHub
Logging a node Error object results in an empty message: Example: ... Exception handling not working with Node 9.8 #1312.
Read more >
Beware of Using JSON.stringify() for Logging - Level Up Coding
These error messages were logged using JSON.stringify(). So why does a technique that works great for logging plain objects not work at all...
Read more >
Designing Error Messages and a Logging Strategy in Node.js
Learn how to structure helpful error messages and follow a good logging strategy.
Read more >
Error - JavaScript - MDN Web Docs - Mozilla
Error objects are thrown when runtime errors occur. The Error object can also be used as a base object for user-defined exceptions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found