Hey i am using this winston logger, kindly explain use of level inside the transports, what will happen if i use logger with info while logging, do i have to use debug while i log my data.
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
level: 'debug',
json: true
}),
new (winston.transports.File)({
name: 'order_check',
filename: './logs/order_check.log',
level: 'debug'
})
]
});
logger.log("info","request body");
Hey i am using this winston logger, kindly explain use of level inside the transports, what will happen if i use logger with info while logging, do i have to use debug while i log my data.
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
level: 'debug',
json: true
}),
new (winston.transports.File)({
name: 'order_check',
filename: './logs/order_check.log',
level: 'debug'
})
]
});
logger.log("info","request body");
Share
Improve this question
asked Jan 15, 2016 at 10:54
Vikarn Singh MankotiaVikarn Singh Mankotia
3261 gold badge2 silver badges9 bronze badges
2 Answers
Reset to default 12The level inside your transport indiciates the minimum logging level that transport will "listen out for"
From the documentation: https://github./winstonjs/winston#logging-levels
Each level is given a specific integer priority. The higher the priority the more important the message is considered to be
{ error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 }
So, in your example, your transports are configured for debug: 4
This means it will log levels
- 4 (debug)
- 3 (verbose)
- 2 (info)
- 1 (warn)
- 0 (error)
A good use case for this would be to set one transport (Console
, for example) to debug and your other to info.
This would output all debug
information to the console, but log only info
to file, preventing log file clutter.
the logging level reflects the importance of the logging message for example, debug is used for non important messages, used for debugging only
info is used for something more important
if you set the logging level to debug then the logs will show debug and info messages (and higher)
if you set the logging level to info then the logs will show only info messages (and higher) - you wont see the debug messages - this helps to avoid clutter in the logs and prevents too much info being shown in the logs in a production environment