Skip to content

Instantly share code, notes, and snippets.

@TwP
Created November 17, 2010 04:58
Show Gist options
  • Save TwP/702996 to your computer and use it in GitHub Desktop.
Save TwP/702996 to your computer and use it in GitHub Desktop.
# Be sure to restart your server when you modify this file
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.8' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
require 'logging-rails'
Rails::Initializer.run do |config|
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
...
end
Logging.show_configuration if Logging.logger[Rails].debug?
require 'logging'
class Rails::Initializer
def load_environment_with_logging
load_environment_without_logging
_fn = File.join(configuration.root_path, 'config', 'logging.rb')
return unless test(?f, _fn)
_log_path = File.dirname(configuration.log_path)
FileUtils.mkdir _log_path if !test(?e, _log_path)
config = configuration
eval(IO.read(_fn), binding, _fn)
silence_warnings { Object.const_set "RAILS_DEFAULT_LOGGER", Logging::Logger[Rails] }
end
alias :load_environment_without_logging :load_environment
alias :load_environment :load_environment_with_logging
# Sets the logger for Active Record, Action Controller, and Action Mailer
# (but only for those frameworks that are to be loaded). If the framework's
# logger is already set, it is not changed.
#
def initialize_framework_logging
for framework in ([ :active_record, :action_controller, :action_mailer ] & configuration.frameworks)
base = framework.to_s.camelize.constantize.const_get("Base")
base.logger ||= Logging::Logger[base]
end
ActiveSupport::Dependencies.logger ||= Logging::Logger[ActiveSupport::Dependencies]
Rails.cache.logger ||= Logging::Logger[Rails.cache]
end
end
# When an object passed as the logging message, use the inspect method to
# convert it to a string. Other format options are :string and :yaml.
#
Logging.format_as :inspect
# Use a layout pattern for injecting a timestamp, log level, and classname
# into the generated log message.
#
layout = Logging.layouts.pattern(:pattern => '[%d] %-5l %c : %m\n')
=begin
Logging.appenders.stdout(
'stdout',
:auto_flushing => true,
:layout => layout
)
=end
# Configure the rolling file appender. Roll the log file each day keeping 7
# days of log files. Do not truncate the log file when it is first opened.
# Flush all log messages immediately to disk (no buffering).
#
Logging.appenders.rolling_file(
'logfile',
:filename => config.log_path,
:keep => 7,
:age => 'daily',
:truncate => false,
:auto_flushing => true,
:layout => layout
)
# Set the root logger to use the rolling file appender, and set the log level
# according to the Rails configuration.
#
Logging.logger.root.level = config.log_level
Logging.logger.root.appenders = %w[logfile]
# Under Phusion Passenger smart spawning, we need to reopen all IO streams
# after workers have forked.
#
# The rolling file appender uses shared file locks to ensure that only one
# process will roll the log file. Each process writing to the file must have
# its own open file descriptor for flock to function properly. Reopening the
# file descriptors after forking ensures that each worker has a unique file
# descriptor.
#
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
Logging.reopen if forked
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment