Create a custom Rails Logger

馋奶兔 提交于 2019-12-08 05:44:26

You can set the Rails logger globally with:

Rails.logger = ...

or you can put it into an environment file, e.g. in config/environments/development.rb

MyApp::Application.configure do
  config.logger = ...
end

Next, Log4r is a separate gem that does not come with Rails. If you want to use it, add it to your Gemfile:

gem "log4r", "~> 1.1.10"

Why would somebody want to substitute an existing logger?

Because loggers have a different set of features. You might want to use a custom logger to upload the logs to an external service, process it etc.

You need to require log4r in application.rb. I am assuming you have installed the gem. then in application.rb

 require 'log4r'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!