Rails3 custom logging options?

What are the “optimal” logging options for Rails3? Someone can suggest good gems or methods for registering.

In general, what is an agreement for custom, uncontrolled, non-model materials? If I create my own registrar as follows:

#custom_logger.rb
class CustomLogger < Logger
  def format_message(severity, timestamp, progname, msg)
    "#{msg}\n"
  end
end

logfile = File.open(RAILS_ROOT + '/log/custom.log', 'a')  #create log file
logfile.sync = true  #automatically flushes data to file
CUSTOM_LOGGER = CustomLogger.new(logfile)  #constant accessible anywhere

(stolen from here ) Should this go in the file in "/ lib"? In the "application.rb"? Or in the initializer?

I cannot find anything that describes these small differences from previous versions of Rails.

thank

+3
source share
3 answers

'lib' still seems like a good place to post this stuff.

Cm:

Rails 3?

+1

I put mine in application.rb because it is only a few lines. I am lazy. If you put your class in a file in lib /, you will have to manually either it or configure lib / autoloading.

Here is my registrar code:

application.rb:

class DreamLogFormatter < Logger::Formatter
  def call(severity, time, progname, msg)
    "[%s(%d)%5s] %s\n" % [time.to_s(:short), $$, severity, msg2str(msg)]
  end
end

....

config.logger = Logger.new(Rails.root.join('log', "#{Rails.env}.log"), 10, 30*1024*1024)
config.logger.formatter = DreamLogFormatter.new

Please note that I roll logs every 30 MB and keep the last 10 logs.

+2
source

Source: https://habr.com/ru/post/1790792/


All Articles