Skip to content
Browse files

Consistently use the framework's configured logger and avoid revertin…

…g to RAILS_DEFAULT_LOGGER unless necessary.
  • Loading branch information...
1 parent a4da817 commit c1a8690d582c08777055caf449c03f85b4c8aa4b @josh josh committed Aug 18, 2008
View
4 actionpack/lib/action_controller/dispatcher.rb
@@ -24,7 +24,7 @@ def define_dispatcher_callbacks(cache_classes)
to_prepare(:activerecord_instantiate_observers) { ActiveRecord::Base.instantiate_observers }
end
- after_dispatch :flush_logger if defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER.respond_to?(:flush)
+ after_dispatch :flush_logger if Base.logger && Base.logger.respond_to?(:flush)
end
# Backward-compatible class method takes CGI-specific args. Deprecated
@@ -142,7 +142,7 @@ def cleanup_application
end
def flush_logger
- RAILS_DEFAULT_LOGGER.flush
+ Base.logger.flush
end
protected
View
3 actionpack/lib/action_view/base.rb
@@ -169,6 +169,7 @@ class Base
class << self
delegate :erb_trim_mode=, :to => 'ActionView::TemplateHandlers::ERB'
+ delegate :logger, :to => 'ActionController::Base'
end
def self.cache_template_loading=(*args)
@@ -328,7 +329,7 @@ def pick_template(template_path)
else
template = Template.new(template_path, view_paths)
- if self.class.warn_cache_misses && logger = ActionController::Base.logger
+ if self.class.warn_cache_misses && logger
logger.debug "[PERFORMANCE] Rendering a template that was " +
"not found in view path. Templates outside the view path are " +
"not cached and result in expensive disk operations. Move this " +
View
2 actionpack/lib/action_view/paths.rb
@@ -3,7 +3,7 @@ class PathSet < ActiveSupport::TypedArray #:nodoc:
def self.type_cast(obj)
if obj.is_a?(String)
if Base.warn_cache_misses && defined?(Rails) && Rails.initialized?
- Rails.logger.debug "[PERFORMANCE] Processing view path during a " +
+ Base.logger.debug "[PERFORMANCE] Processing view path during a " +
"request. This an expense disk operation that should be done at " +
"boot. You can manually process this view path with " +
"ActionView::Base.process_view_paths(#{obj.inspect}) and set it " +
View
2 actionpack/lib/action_view/renderable.rb
@@ -72,7 +72,7 @@ def #{render_symbol}(local_assigns)
end_src
begin
- logger = ActionController::Base.logger
+ logger = Base.logger
logger.debug "Compiling template #{render_symbol}" if logger
ActionView::Base::CompiledTemplates.module_eval(source, filename, 0)
View
4 activerecord/test/connections/native_mysql/connection.rb
@@ -2,9 +2,7 @@
require_dependency 'models/course'
require 'logger'
-RAILS_DEFAULT_LOGGER = Logger.new('debug.log')
-RAILS_DEFAULT_LOGGER.level = Logger::DEBUG
-ActiveRecord::Base.logger = RAILS_DEFAULT_LOGGER
+ActiveRecord::Base.logger = Logger.new("debug.log")
# GRANT ALL PRIVILEGES ON activerecord_unittest.* to 'rails'@'localhost';
# GRANT ALL PRIVILEGES ON activerecord_unittest2.* to 'rails'@'localhost';
View
16 activeresource/lib/active_resource/connection.rb
@@ -28,24 +28,24 @@ def to_s; @message ;end
# 3xx Redirection
class Redirection < ConnectionError # :nodoc:
- def to_s; response['Location'] ? "#{super} => #{response['Location']}" : super; end
- end
+ def to_s; response['Location'] ? "#{super} => #{response['Location']}" : super; end
+ end
# 4xx Client Error
class ClientError < ConnectionError; end # :nodoc:
-
+
# 400 Bad Request
class BadRequest < ClientError; end # :nodoc
-
+
# 401 Unauthorized
class UnauthorizedAccess < ClientError; end # :nodoc
-
+
# 403 Forbidden
class ForbiddenAccess < ClientError; end # :nodoc
-
+
# 404 Not Found
class ResourceNotFound < ClientError; end # :nodoc:
-
+
# 409 Conflict
class ResourceConflict < ClientError; end # :nodoc:
@@ -201,7 +201,7 @@ def authorization_header
end
def logger #:nodoc:
- ActiveResource::Base.logger
+ Base.logger
end
end
end
View
4 activesupport/lib/active_support/cache/file_store.rb
@@ -17,7 +17,7 @@ def write(name, value, options = nil)
ensure_cache_path(File.dirname(real_file_path(name)))
File.atomic_write(real_file_path(name), cache_path) { |f| Marshal.dump(value, f) }
rescue => e
- RAILS_DEFAULT_LOGGER.error "Couldn't create cache directory: #{name} (#{e.message})" if RAILS_DEFAULT_LOGGER
+ logger.error "Couldn't create cache directory: #{name} (#{e.message})" if logger
end
def delete(name, options = nil)
@@ -67,4 +67,4 @@ def search_dir(dir, &callback)
end
end
end
-end
+end
View
8 activesupport/lib/active_support/core_ext/kernel/debugger.rb
@@ -2,12 +2,12 @@ module Kernel
unless respond_to?(:debugger)
# Starts a debugging session if ruby-debug has been loaded (call script/server --debugger to do load it).
def debugger
- RAILS_DEFAULT_LOGGER.info "\n***** Debugger requested, but was not available: Start server with --debugger to enable *****\n"
+ Rails.logger.info "\n***** Debugger requested, but was not available: Start server with --debugger to enable *****\n"
end
end
-
+
def breakpoint
- RAILS_DEFAULT_LOGGER.info "\n***** The 'breakpoint' command has been renamed 'debugger' -- please change *****\n"
+ Rails.logger.info "\n***** The 'breakpoint' command has been renamed 'debugger' -- please change *****\n"
debugger
end
-end
+end
View
10 activesupport/lib/active_support/dependencies.rb
@@ -39,6 +39,10 @@ module Dependencies #:nodoc:
mattr_accessor :explicitly_unloadable_constants
self.explicitly_unloadable_constants = []
+ # The logger is used for generating information on the action run-time (including benchmarking) if available.
+ # Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
+ mattr_accessor :logger
+
# Set to true to enable logging of const_missing and file loads
mattr_accessor :log_activity
self.log_activity = false
@@ -584,7 +588,7 @@ def remove_constant(const) #:nodoc:
protected
def log_call(*args)
- if defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER && log_activity
+ if logger && log_activity
arg_str = args.collect { |arg| arg.inspect } * ', '
/in `([a-z_\?\!]+)'/ =~ caller(1).first
selector = $1 || '<unknown>'
@@ -593,8 +597,8 @@ def log_call(*args)
end
def log(msg)
- if defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER && log_activity
- RAILS_DEFAULT_LOGGER.debug "Dependencies: #{msg}"
+ if logger && log_activity
+ logger.debug "Dependencies: #{msg}"
end
end
end
View
4 railties/lib/fcgi_handler.rb
@@ -18,7 +18,6 @@ class RailsFCGIHandler
attr_accessor :log_file_path
attr_accessor :gc_request_period
-
# Initialize and run the FastCGI instance, passing arguments through to new.
def self.process!(*args, &block)
new(*args, &block).process!
@@ -68,7 +67,6 @@ def process!(provider = FCGI)
end
end
-
protected
def process_each_request(provider)
cgi = nil
@@ -197,7 +195,7 @@ def restart!
# close resources as they won't be closed by
# the OS when using exec
logger.close rescue nil
- RAILS_DEFAULT_LOGGER.close rescue nil
+ Rails.logger.close rescue nil
exec(command_line)
end
View
15 railties/lib/initializer.rb
@@ -33,7 +33,11 @@ def initialized=(initialized)
end
def logger
- RAILS_DEFAULT_LOGGER
+ if defined?(RAILS_DEFAULT_LOGGER)
+ RAILS_DEFAULT_LOGGER
+ else
+ nil
+ end
end
def root
@@ -403,7 +407,7 @@ def initialize_framework_caches
# +STDERR+, with a log level of +WARN+.
def initialize_logger
# if the environment has explicitly defined a logger, use it
- return if defined?(RAILS_DEFAULT_LOGGER)
+ return if Rails.logger
unless logger = configuration.logger
begin
@@ -431,10 +435,11 @@ def initialize_logger
# RAILS_DEFAULT_LOGGER.
def initialize_framework_logging
for framework in ([ :active_record, :action_controller, :action_mailer ] & configuration.frameworks)
- framework.to_s.camelize.constantize.const_get("Base").logger ||= RAILS_DEFAULT_LOGGER
+ framework.to_s.camelize.constantize.const_get("Base").logger ||= Rails.logger
end
- RAILS_CACHE.logger ||= RAILS_DEFAULT_LOGGER
+ ActiveSupport::Dependencies.logger ||= Rails.logger
+ Rails.cache.logger ||= Rails.logger
end
# Sets +ActionController::Base#view_paths+ and +ActionMailer::Base#template_root+
@@ -531,7 +536,7 @@ def prepare_dispatcher
return unless configuration.frameworks.include?(:action_controller)
require 'dispatcher' unless defined?(::Dispatcher)
Dispatcher.define_dispatcher_callbacks(configuration.cache_classes)
- Dispatcher.new(RAILS_DEFAULT_LOGGER).send :run_callbacks, :prepare_dispatch
+ Dispatcher.new(Rails.logger).send :run_callbacks, :prepare_dispatch
end
def disable_dependency_loading

0 comments on commit c1a8690

Please sign in to comment.
Something went wrong with that request. Please try again.