I'm using Winston in Node.js for logging. I know I can add metadata individually to each log message but is there a way to specify a default set of metadata that'll be added to every log message (such as the app name) as I don't want to specify it every time I need to send a log message.
For Winston v2 (see comments)
There are now rewriters
.
For example, the below will add a property app
to every metadata going through this logger.
logger.rewriters.push(function(level, msg, meta) {
meta.app = 'myApp';
return meta;
});
You can also declare it when building the logger:
new (winston.Logger)({
level: config.log[file].level,
rewriters: [
(level, msg, meta) => {
meta.app = 'myApp';
return meta;
}
],
transports: [
/*your transports*/
]
});