Skip to content

broadcast doesn't work with child #134

@The-Alchemist

Description

@The-Alchemist

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions