Rotate log files on production and staging
The code based on the logger Rails uses by default; as mentioned in the Rails configuration guide: > [the logger] defaults to an instance of ActiveSupport::TaggedLogging > that wraps an instance of ActiveSupport::Logger which outputs a log to > the log/ directory. You can supply a custom logger, to get full > compatibility you must follow these guidelines: > > * To support a formatter, you must manually assign a formatter from > the config.log_formatter value to the logger. > * To support tagged logs, the log instance must be wrapped with > ActiveSupport::TaggedLogging. > * To support silencing, the logger must include > ActiveSupport::LoggerSilence module. The ActiveSupport::Logger class > already includes these modules.
This commit is contained in:
@@ -87,6 +87,11 @@ Rails.application.configure do
|
||||
# Use default logging formatter so that PID and timestamp are not suppressed.
|
||||
config.log_formatter = ::Logger::Formatter.new
|
||||
|
||||
# Rotate logger
|
||||
logger = ActiveSupport::Logger.new(config.default_log_file, "daily")
|
||||
logger.formatter = config.log_formatter
|
||||
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
||||
|
||||
# Use a different logger for distributed setups.
|
||||
# require "syslog/logger"
|
||||
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")
|
||||
|
||||
@@ -86,6 +86,11 @@ Rails.application.configure do
|
||||
# Use default logging formatter so that PID and timestamp are not suppressed.
|
||||
config.log_formatter = ::Logger::Formatter.new
|
||||
|
||||
# Rotate logger
|
||||
logger = ActiveSupport::Logger.new(config.default_log_file, "daily")
|
||||
logger.formatter = config.log_formatter
|
||||
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
||||
|
||||
# Use a different logger for distributed setups.
|
||||
# require "syslog/logger"
|
||||
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")
|
||||
|
||||
Reference in New Issue
Block a user