initialize_logger()
public
If the RAILS_DEFAULT_LOGGER constant is already set, this
initialization routine does nothing. If the constant is not set, and
Configuration#logger is not nil, this also does nothing.
Otherwise, a new logger
instance is created at Configuration#log_path, with a default log level of
Configuration#log_level.
If the log could not be created, the log will be set to output to
STDERR, with a log level of WARN.
Show source
def initialize_logger
return if defined?(RAILS_DEFAULT_LOGGER)
unless logger = configuration.logger
begin
logger = ActiveSupport::BufferedLogger.new(configuration.log_path)
logger.level = ActiveSupport::BufferedLogger.const_get(configuration.log_level.to_s.upcase)
logger.auto_flushing = false if configuration.environment == "production"
rescue StandardError =>e
logger = ActiveSupport::BufferedLogger.new(STDERR)
logger.level = ActiveSupport::BufferedLogger::WARN
logger.warn(
"Rails Error: Unable to access log file. Please ensure that #{configuration.log_path} exists and is chmod 0666. " +
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
)
end
end
silence_warnings { Object.const_set "RAILS_DEFAULT_LOGGER", logger }
end