Module: Logging::Rails::Mixin
- Defined in:
- lib/logging/rails/mixin.rb
Overview
Include this module into your ApplicationController to provide per-controller log level configurability. You can also include this module into your models or anywhere else you would like to control the log level.
Alternatively, you can use the ‘include Logging.globally` trick to add a `logger` method to every Object in the ruby interpreter. See github.com/TwP/logging/blob/master/lib/logging.rb#L194 for more details.
Constant Summary collapse
- LOGGER_METHOD =
RUBY_VERSION < '1.9' ? 'logger' : :logger
Class Method Summary collapse
-
.extended(other) ⇒ Object
This method is called when the modules is extended into another class or module.
-
.included(other) ⇒ Object
This method is called when the module is included into a class.
Instance Method Summary collapse
-
#logger ⇒ Object
Returns the logger instance.
Class Method Details
.extended(other) ⇒ Object
This method is called when the modules is extended into another class or module. It will remove any existing ‘logger` method and insert its own version.
25 26 27 28 |
# File 'lib/logging/rails/mixin.rb', line 25 def self.extended( other ) eigenclass = class << other; self; end eigenclass.__send__(:remove_method, LOGGER_METHOD.to_sym) if eigenclass.instance_methods.include? LOGGER_METHOD end |
.included(other) ⇒ Object
This method is called when the module is included into a class. It will extend the including class so it also has a class-level ‘logger` method.
17 18 19 20 |
# File 'lib/logging/rails/mixin.rb', line 17 def self.included( other ) other.__send__(:remove_method, LOGGER_METHOD.to_sym) if other.instance_methods.include? LOGGER_METHOD other.extend self end |
Instance Method Details
#logger ⇒ Object
Returns the logger instance.
31 32 33 |
# File 'lib/logging/rails/mixin.rb', line 31 def logger @logger ||= ::Logging::Logger[self] end |