Error objects are not logged
See original GitHub issuePlease 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:
- Created 5 years ago
- Reactions:8
- Comments:6 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
still not fixed 😕
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!