Class: Log4jruby::Rails
- Inherits:
-
Object
- Object
- Log4jruby::Rails
- Defined in:
- lib/log4jruby/rails.rb
Overview
Configure Rails logging from a config/initializers file
Setting up log4j using config.logger from within the Rails initialization process may not be possible if the CLASSPATH has not yet been setup. This class can be used to configure the logging from within a config/initializers/ file.
ex.
require 'log4jruby/rails'
Log4jruby::Rails.configure do |c|
c.logger_name = 'MyApp'
end
Instance Attribute Summary collapse
-
#logger_name ⇒ String
Default is ‘Rails’.
-
#tracing ⇒ String
Defaults to false in ‘production’ or true otherwise.
Class Method Summary collapse
-
.configure {|config| ... } ⇒ Object
Sets rails Base loggers(e.g. ActionController::Base, ActiveRecord::Base, etc).
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ Rails
constructor
:nodoc:.
Constructor Details
#initialize {|_self| ... } ⇒ Rails
:nodoc:
25 26 27 28 29 30 |
# File 'lib/log4jruby/rails.rb', line 25 def initialize #:nodoc: @logger_name = 'Rails' @tracing = (::Rails.env != 'production') yield(self) end |
Instance Attribute Details
#logger_name ⇒ String
Default is ‘Rails’
22 23 24 |
# File 'lib/log4jruby/rails.rb', line 22 def logger_name @logger_name end |
#tracing ⇒ String
Defaults to false in ‘production’ or true otherwise
22 23 24 |
# File 'lib/log4jruby/rails.rb', line 22 def tracing @tracing end |
Class Method Details
.configure {|config| ... } ⇒ Object
Sets rails Base loggers(e.g. ActionController::Base, ActiveRecord::Base, etc)
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/log4jruby/rails.rb', line 38 def configure(&block) config = new(&block) Logger.root.tracing = config.tracing logger = Log4jruby::Logger.get(config.logger_name) set_logger('ActionController', logger) set_logger('ActiveRecord', logger) set_logger('ActiveResource', logger) set_logger('ActionMailer', logger) end |