I need to add a custom log level like "verbose" or "traffic" to ruby logger, how to do?
相关问题
- I want to trace logs using a Macro multi parameter
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
- reference to a method?
- Error message 'No handlers could be found for
相关文章
- how do I log requests and responses for debugging
- Ruby using wrong version of openssl
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- “No explicit conversion of Symbol into String” for
- Segmentation fault with ruby 2.0.0p247 leading to
- How to detect if an element exists in Watir
- uninitialized constant Mysql2::Client::SECURE_CONN
If you start needing a bunch of custom stuff, it may be worth checking out log4r, which is a flexible logging library that lets you do a bunch of interesting/useful stuff easily.
You can create your own logger by overloading the Logger class
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 atrace
log levelThis is using the
2.0.0
of thelogging
gem.Your own logger just need to overwrite the
Logger#format_severity
method, something like this :You can simply add to the Logger class:
Log levels are nothing but integer constants defined in
logger.rb
:You can log messages with any level you like using
Logger#add
method: