-
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
how to add timestamp to logged output? #906
Comments
You can do it manually if you want fine-grained control over your output:
Or the easy (and probably more consistent way) is just to set
|
I normally create a custom logger module.exports = new (winston.Logger)({
level: 'info',
handleExceptions: false,
transports: [
new (winston.transports.Console)({
timestamp() {
return moment().format('YYYY-MM-DD HH:mm:ss.SSSS');
},
formatter(params) {
// Options object will be passed to the format function.
// It's general properties are: timestamp, level, message, meta.
const meta = params.meta !== undefined ? util.inspect(params.meta, { depth: null }) : '';
return `[${params.timestamp}] [${params.level}] [${pkg.name}] *** ${params.message} ${meta}`;
},
}),
],
}); |
Thanks @osukaa . I realized I need to require() 'moment' (3rd party module) and 'util' (Node.js) module. |
|
In |
No description provided.
The text was updated successfully, but these errors were encountered: