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

Child loggers will not emit on parent after addStream() #479

Closed
thanpolas opened this issue Feb 6, 2017 · 2 comments
Closed

Child loggers will not emit on parent after addStream() #479

thanpolas opened this issue Feb 6, 2017 · 2 comments

Comments

@thanpolas
Copy link

I'm using Bunyan for the purposes of an npm library. I have set it up so as to provide child-loggers for each module, and then expose the root logger.

When a stream is attached to the root logger using addStream() it will not receive any messages logged by the child loggers.

You can reproduce with the following snippet:

var rootLogger = bunyan.createLogger({
  name: 'root',
  level: 'info',
  // Mute logger
  streams: [],
});

var childLog = rootLogger.child({module: 'child-module'});

rootLogger.addStream({
  type: 'stream',
  stream: process.stdout,
}, 'debug');

childLog.debug('Hello there');
childLog.info('Hello there');
childLog.warn('Hello there');
childLog.error('Hello there');

console.log('should have logged');
thanpolas added a commit to waldophotos/kafka-avro that referenced this issue Feb 6, 2017
@thanpolas
Copy link
Author

@trentm can you please confirm this is a bug and not bad-usage? Are there any practical workarounds to my use case so I can get unblocked by this? (provide logs from my library).

@trentm
Copy link
Owner

trentm commented Mar 8, 2017

@thanpolas Sorry for the delay in responding.

As I mentioned in another issue you opened, the intended way to structure libraries is to allow them to take a Bunyan logger instance (created by whatever application or script is using the library), and log on that. This gives the application responsibility (and control) for setting the output streams for logging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants