How to add a custom log level to logger in ruby?

后端 未结 6 436

I need to add a custom log level like \"verbose\" or \"traffic\" to ruby logger, how to do?

6条回答
  •  遥遥无期
    2021-01-11 15:48

    This is an old question, but since it comes up so high on google, I figured it'd be useful to have to correct answer. You can actually use the Logging.init method. Here's how you would add a trace log level

    require 'logging'
    Logging.init %w(trace debug info warn error fatal)
    Logging.logger.root.level = :trace
    Logging.logger.root.add_appenders Logging.appenders.stdout
    Logging.logger['hello'].trace 'TEST'
    

    This is using the 2.0.0 of the logging gem.

提交回复
热议问题