Module: LogSwitch
- Defined in:
- lib/log_switch.rb,
lib/log_switch/version.rb
Overview
LogSwitch mixes a logger into a class/module and, most importantly, allows for turning off logging programmatically. See README.md for more info.
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Constant Summary collapse
- VERSION =
'1.1.0'
Class Method Summary collapse
- .included(base) ⇒ Object
-
.logger ⇒ Object
Defaults to a
Loggerwriting to STDOUT. - .logger=(new_logger) ⇒ Object
-
.reset_config! ⇒ Object
Sets back to defaults.
Class Method Details
.included(base) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/log_switch.rb', line 7 def self.included(base) @includers ||= [] @includers << base base.extend ClassMethods base.send(:include, InstanceMethods) base.class_eval do def self.included(b) b.extend ClassMethods b.send :include, InstanceMethods end end end |
.logger ⇒ Object
Defaults to a Logger writing to STDOUT.
22 23 24 |
# File 'lib/log_switch.rb', line 22 def self.logger @logger ||= ::Logger.new STDOUT end |
.logger=(new_logger) ⇒ Object
26 27 28 |
# File 'lib/log_switch.rb', line 26 def self.logger=(new_logger) @logger = new_logger end |
.reset_config! ⇒ Object
Sets back to defaults.
31 32 33 34 35 36 37 38 |
# File 'lib/log_switch.rb', line 31 def self.reset_config! self.logger = ::Logger.new STDOUT @includers.each do |klass| klass.logging_enabled = false klass.log_class_name = true end end |