Create logger with a transport with lower log level than log level of logger: unexpected behaviour?
See original GitHub issueI create a logger with level=info
, but I add a transport using `level=debug’. Three files are created:
- error.log: contains only error level logs. this is expected behavior right?
- debug.log: contains error, warn, info, verbose and debug logs
- combined.log: contains errors up until info as expected
I expected error.log to only contain debug level logs because I assumed the top level info is filtered for debug only for that transport. But why then does my transport for debug contain all other logs up until debug? Is this expected or a bug?
const winston = require('winston');
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
transports: [
new winston.transports.File({ filename: 'error.log', level: 'error' }),
new winston.transports.File({ filename: 'debug.log', level: 'debug' }),
new winston.transports.File({ filename: 'combined.log' }),
],
});
logger.error('error');
logger.warn('warn');
logger.info('info');
logger.verbose('verbose');
logger.debug('debug');
logger.silly('silly');
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Logging Levels: What They Are & How to Choose Them
WARN – the log level that indicates that something unexpected happened in the application, a problem, or a situation that might disturb one...
Read more >NLog unexpectedly writing to log with lower level restriction
What's happening is that when I get the logger for "commands" and I check its properties every log level is enabled, so if...
Read more >Log Levels Explained and How to Use Them - Better Stack
Log levels are labels that indicate the severity or urgency of a log entry. This article will help you understand why they are...
Read more >Classic Logging - Documentation - Akka
Auxiliary logging options. Akka has a few configuration options for very low level debugging. These make more sense in development than in production....
Read more >Configure logging | Filebeat Reference [8.5] - Elastic
Filebeat only creates a log file if there is logging output. For example, if you set the log level to error and there...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
From the readme:
And description for e.g. log level for console transport:
I also expected the level on the logger object to be a kind of filter, and no matter what the transports are, they will never get anything above this level.
If this is just a default for all transport levels of that logger that’s fine - but it could be documented better 😃
You are setting maximum reported level for each transport. The most severe messages have the lowest level (
emerg
=0
), and the least important, the higher the level is (debug
=7
).That being said - if you set one transport to
error
(3
) level and other todebug
(7
), first one will get onlyerror
and lower (more severe) messages, whilst the other one will getdebug
,info
,warn
,error
… and so on. One transport doesn’t filter out the other one.The
level
at the logger level is the default that can be overriden at the transport level.For me everything seems to work as expected.
https://github.com/winstonjs/winston#using-logging-levels