Someting like a tee functionality in logger.
相关问题
- 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
One more option ;-)
@David's solution is very good. I've made a generic delegator class for multiple targets based on his code.
This is a simplification of @rado's solution.
It has all the same benefits as his without the need of the outer class wrapper. Its a useful utility to have in a separate ruby file.
Use it as a one-liner to generate delegator instances like so:
OR use it as a factory like so:
If you're in Rails 3 or 4, as this blog post points out, Rails 4 has this functionality built in. So you can do:
Or if you're on Rails 3, you can backport it:
You can also add multiple device logging functionality directly into the Logger:
For instance:
I have written a little RubyGem that allows you to do several of these things:
You can find the code on github: teerb