question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create logger with a transport with lower log level than log level of logger: unexpected behaviour?

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
ThomasKrueglcommented, May 30, 2018

From the readme:

A logger accepts the following parameters: level […] Log only if info.level less than or equal to this level

And description for e.g. log level for console transport:

level: Level of messages that this transport should log (default ‘info’).

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 😃

2reactions
j3bb9zcommented, May 29, 2018

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 to debug (7), first one will get only error and lower (more severe) messages, whilst the other one will get debug, 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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found