Custom logger in Rails 3?

前端 未结 2 1737
-上瘾入骨i
-上瘾入骨i 2020-12-30 12:11

I want to have a custom logger for my application, which of course logs to a different file, someone asked a question: Setting up the logger in rails 3

But I want to

相关标签:
2条回答
  • 2020-12-30 12:31

    You mean, like having in application.rb:

    StatusLogger = ActiveSupport::BufferedLogger.new(Rails.root.join('log/status.log'))
    
    0 讨论(0)
  • 2020-12-30 12:46

    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.

    0 讨论(0)
提交回复
热议问题