-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log an error without stack and other properties #1451
Comments
This is by design. If I understand correctly, you just want to log the error message without the other error properties. In that case, I would recommend just logging err.message or whatever property you desire, rather than logging the entire error object. |
@DABH what to do if i want to log an error with stack trace and other properties?
Is only going to log "whatever" and i am losing my stack trace. Because of this line: https://github.com/winstonjs/winston/blob/master/lib/winston/create-logger.js#L52 |
I think there is an unresolved issue there. I'm looking into it. Looks like this is the kind of workaround you need to do for now since Error properties are non-enumerable for some reason (thanks JS designers): const winston = require('winston');
const format = winston.format;
const enumerateErrorFormat = format(info => {
if (info.message instanceof Error) {
info.message = Object.assign({
message: info.message.message,
stack: info.message.stack
}, info.message);
}
if (info instanceof Error) {
return Object.assign({
message: info.message,
stack: info.stack
}, info);
}
return info;
});
const logger = winston.createLogger({
level: 'debug',
format: format.combine(
enumerateErrorFormat(),
format.json()
),
transports: [
new winston.transports.Console(),
],
});
logger.log('error', new Error('whatever')); See #1338 . I'll see what I can do about figuring out a better solution for |
Thx @DABH for pointing to the correct issue, indeed this workaround seem to work. |
winston@3
When I log an error, and then the var
info
become an error, I expect theinfo.message
is errorThe text was updated successfully, but these errors were encountered: