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

broadcast doesn't work with child #134

Open
The-Alchemist opened this issue Aug 18, 2022 · 0 comments
Open

broadcast doesn't work with child #134

The-Alchemist opened this issue Aug 18, 2022 · 0 comments

Comments

@The-Alchemist
Copy link
Contributor

The-Alchemist commented Aug 18, 2022

From the README, but using .child():

logger = Ougai::Logger.new(STDOUT)
logger.level = Logger::INFO

error_logger = Ougai::Logger.new('./error.log')
error_logger.level = Logger::ERROR
logger.extend Ougai::Logger.broadcast(error_logger)

# start a child logger

child_logger = logger.child(child: true)

loggechild_loggerr.info('Hello!')

child_logger.error('Failed to do something.')

child_logger.level = Logger::WARN # error_logger level is also set WARN by propagation
child_logger.warn('Ignored something.')

Stdout output

{"name":"test","hostname":"karl-pietrzaks-mbp.local","pid":73910,"level":30,"time":"2022-08-18T15:56:24.014-04:00","v":0,"msg":"Hello!","child":true}
{"name":"test","hostname":"karl-pietrzaks-mbp.local","pid":73910,"level":50,"time":"2022-08-18T15:56:24.014-04:00","v":0,"msg":"Failed to do something.","child":true}
{"name":"test","hostname":"karl-pietrzaks-mbp.local","pid":73910,"level":40,"time":"2022-08-18T15:56:24.015-04:00","v":0,"msg":"Ignored something.","child":true}

error.log

# Logfile created on 2022-08-18 15:56:08 -0400 by logger.rb/66358

Is this intentional? I assumed creating a child logger would broadcast as well. Thoughts?

Use Case

I have a central setup_logging.rb file that sets up multiple loggers, and then:

  1. each module require's setup_logging
  2. sets up a child logger for itself
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant