I am using winston to handle my logging for my nodejs backend. in my case i created some custom levels to have logs written to a more specific category like security , db etc. All works fine, except that I would like to specify a extra label when i write to file like severity. So in my case I use the label like security to write all security related messages to the file. Both of the below calls do the same in my case
logger.security( 'We have the latest db vesion ' + Date())
logger.log('security','We have the latest db vesion ' + Date());
And produce an output in log file like this
2021-01-28 15:05:29.869 [undefined] security: We have the latest db vesion Thu Jan 28 2021 15:05:29 GMT-0800 (Pacific Standard Time)
myFormat looks like this
const myFormat = printf(({ level, message, label, timestamp }) => {
return `${timestamp} [${label}] ${level}: ${message}`;
})
So my question is how can I pass the label to the log when i call the log function ? Also is there a way to apply a color to my label ? I am planning to use the label to specify the severity of the log entry like info or error in my security log.