Error logging method does not logs Error instance correctly
See original GitHub issuePlease tell us about your environment:
-
winston
version? 3.1.0-
winston@2
-
winston@3
-
-
node -v
outputs: v8.11.3 -
Operating System? Linux
-
Language? all
What is the problem?
logger.error
called with Error
instance doesn’t use message
and stack
fields, instead logs test error
.
Code example:
const winston = require('winston');
const alignedWithColorsAndTime = winston.format.combine(
// winston.format.colorize({ all: true }),
// winston.format.timestamp(),
// winston.format.align(),
winston.format.printf((info) => {
const { level, message, ...args } = info;
if (level.indexOf('error') !== -1) {
console.log(typeof message, JSON.stringify(message));
}
return `[${level}]: ${message} ${Object.keys(args).length ? JSON.stringify(args, null, 2) : ''}`;
})
);
const transports = [new winston.transports.Console({
level: 'debug',
format: alignedWithColorsAndTime
})];
const logger = winston.createLogger({
level: 'debug',
transports
});
try {
logger.info('aaaaa');
logger.debug('bbbb');
logger.error('eeee');
throw new Error('Scary error');
} catch (error) {
logger.error(error);
}
What do you expect to happen instead?
At least actual error message logged. Ideally - with stack.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:34 (3 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 ...
Read more >How to Log Exception Properly - Medium
The problem with this is developer would not know that an error has happened. Common Mistake 2: Only log developer's message. log.error(" ...
Read more >Access and Error Logs - The Ultimate Guide To Logging - Loggly
Access and Error Logs. Log Files. An Apache log is a record of the events that have occurred on your Apache web server....
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 >Sitecore.Diagnostics.Log.Error() method is not working Inside ...
Actually, recommended practice would be to use a Namespace as your logger, as opposed to new object() or anything else.
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
Had same issue, I had to implement
logger.error
myself:Suggesting this be closed due to #1576.
Can use the formatters.