-
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
fix: append error cause when using logger.child()
#2467
base: master
Are you sure you want to change the base?
Conversation
Just tried to run it here and got Runtime
Minimum Working Exampleconst winston = require('winston')
const logger = winston.createLogger({
format: winston.format.combine(
winston.format.json(),
),
transports: [
new winston.transports.Console(),
],
})
const childLogger = logger.child()
const error = new Error('Something went wrong', { cause: new Error('The devil is in the details') })
childLogger.error(error) Output{"cause":{},"level":"error","message":"Something went wrong","stack":"Error: Something went wrong\n at Object.<anonymous> (/home/Code/winston-debug/index.js:14:15)\n at Module._compile (node:internal/modules/cjs/loader:1546:14)\n at Object..js (node:internal/modules/cjs/loader:1689:10)\n at Module.load (node:internal/modules/cjs/loader:1318:32)\n at Function._load (node:internal/modules/cjs/loader:1128:12)\n at TracingChannel.traceSync (node:diagnostics_channel:315:14)\n at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5)\n at node:internal/main/run_main_module:36:49"} |
Hi @HenriqueSilverio , const winston = require('./lib/winston')
class CustomTransport extends winston.Transport {
log(info, callback) {
const { level, message, stack, cause } = info;
console.error({
level,
message,
stack,
});
if (cause) {
console.error({
level,
message: cause.message,
stack: cause.stack
})
}
callback(null, true);
}
}
const logger = winston.createLogger({
format: winston.format.combine(
winston.format.json(),
),
transports: [
new CustomTransport(),
],
})
const childLogger = logger.child()
const error = new Error('Something went wrong', { cause: new Error('The devil is in the details') })
childLogger.error(error) |
Hi @2013xile! |
Without the changes in this PR, even a custom transport cannot retrieve the |
Got it! I've tried here and it worked as you said. Thanks for clarifying that! |
Add
error.cause
when cloning error info inlogger.child()