How do I use a custom log for my rake tasks in Ruby on Rails?

二次信任 提交于 2019-12-08 17:27:40

rake disables logging in production mode. make sure you're running in development mode if you want it to log

  1. What do you mean by "does not work for me"? I just tried this same code and it worked - created a new log file and put some text in it.
  2. @@logger is a class variable, it's a language issue, not Rails' one. I believe there's no need in further explanations :)
  3. You've probably mistaken typing "function helloworld2" :)

Advanced Rails Recipes Recipe 84 from @topfunky shows how to define a custom logger. He has some code in the environment config file (production would look like this): RAILS_ROOT/config/environments/production.rb:

config.logger = RAILS_DEFAULT_LOGGER = Logger.new(config.log_path)

I'd test that out instead of redefining the class variable as you have. He might have something on http://nubyonrails.com to check as well.

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