Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger level doesn't update transports level #1191

Closed
emmanueldiaz opened this issue Jan 25, 2018 · 1 comment · Fixed by #1328
Closed

Logger level doesn't update transports level #1191

emmanueldiaz opened this issue Jan 25, 2018 · 1 comment · Fixed by #1328
Labels
Bug Good First Issue Good issue for new contributors Help Wanted Additional help desired from the community Important

Comments

@emmanueldiaz
Copy link

emmanueldiaz commented Jan 25, 2018

I have a scenario where I need multiple loggers in a winston instance.
So let's say you have this code:

const winston = require('winston');

winston.loggers.add('category1', {
  console: {
    colorize: true,
    level: 'info',
    label: 'category one'
  },
  file: {
    filename: '/path/to/some/file'
  }
})

const category1 = winston.loggers.get('category1');

const testLogger = () => {
  category1.debug('debug test');
  category1.info('info test');
  category1.warn('warn test');
  category1.error('error test');
}

At this point category1.level is info because it is the default level assigned to the logger.
So, if we run testLogger() we won't see the debug message.

Let's say that we want to change the logging level to error. If we do category1.level = 'error' now category1.level will be error, but testLogger() will still show info, warn and error messages.

In order to get category1 to only show error we would need to assign category1.transports[0].level = error.

Shouldn't just changing the logger level directly affect the logging level of the attached transports?
If this the expected behavior, then what is the purpose of having a level for the logger itself?

@emmanueldiaz emmanueldiaz changed the title Logger level doesn't update transport level Logger level doesn't update transports level Jan 25, 2018
@indexzero
Copy link
Member

This is a fair point. Under the covers we are using the pipe event to get the initial value from the parent logger in the transports, but the API exposes no way to update all of those transports if you wish.

@indexzero indexzero added the Bug label Apr 19, 2018
@indexzero indexzero added Important Good First Issue Good issue for new contributors Help Wanted Additional help desired from the community labels Apr 22, 2018
indexzero pushed a commit that referenced this issue Jun 12, 2018
* [fix] Update level property to change transport level #1191

* [test] Add a test case for Logger level setting transports level

* [test] tiny change in testcase for Logger level setting transports level

* [refactor test] Remove need for getter and setter now that we check a live reference to the parent in `winston-transport`. Refactor the test to ensure that `"pipe"` has been handled by the child before proceeding.

* [dist] Bump to `winston-transport@4.2.0`
Mizumaki pushed a commit to Mizumaki/winston that referenced this issue Jun 11, 2020
…winstonjs#1328)

* [fix] Update level property to change transport level winstonjs#1191

* [test] Add a test case for Logger level setting transports level

* [test] tiny change in testcase for Logger level setting transports level

* [refactor test] Remove need for getter and setter now that we check a live reference to the parent in `winston-transport`. Refactor the test to ensure that `"pipe"` has been handled by the child before proceeding.

* [dist] Bump to `winston-transport@4.2.0`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Good First Issue Good issue for new contributors Help Wanted Additional help desired from the community Important
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants