开发者

Custom logger in Rails 3?

I want to have a custom logger for my a开发者_如何转开发pplication, which of course logs to a different file, someone asked a question: Setting up the logger in rails 3

But I want to have a logger which I can call with my own class name like:

StatusLogger.info "something happend!!!"

How can I do this?


You could do that with this code

logfile = File.open('/path/to/log.log', 'a')  
StatusLogger = Logger.new(logfile)
StatusLogger.info 'Hello World!'

And you would most likely configure this in an initializer file, or you could do it in an environment file if you wanted.


You mean, like having in application.rb:

StatusLogger = ActiveSupport::BufferedLogger.new(Rails.root.join('log/status.log'))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜