In rails I want to log some information in a different log file and not the standard development.log or production.log. I want to do this logging from a model class.
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Eager-loading association count with Arel (Rails 3
- I want to trace logs using a Macro multi parameter
- Is there a way to remove IDV Tags from an AIFF fil
相关文章
- how do I log requests and responses for debugging
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
- Rspec controller error expecting <“index”> but
Update
I made a gem based on the solution below, called multi_logger. Just do this in the initializer:
and call
and you are done.
If you want to code it yourself, see below:
A more complete solution would be to place the following in your
lib/
orconfig/initializers/
directory.The benefit is that you can setup formatter to prefix timestamps or severity to the logs automatically. This is accessible from anywhere in Rails, and looks neater by using the singleton pattern.
Define a logger class in (say) app/models/special_log.rb:
initialize the logger in (say) config/initializers/special_log.rb:
Anywhere in your app, you can log with:
Here is my custom logger: