How to log something in Rails in an independent log file?

前端 未结 9 1300
栀梦
栀梦 2020-11-30 17:12

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.

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 17:24

    Here is my custom logger:

    class DebugLog
      def self.debug(message=nil)
        return unless Rails.env.development? and message.present?
        @logger ||= Logger.new(File.join(Rails.root, 'log', 'debug.log'))
        @logger.debug(message) 
      end
    end
    

提交回复
热议问题