Module: LogSwitch

Defined in:
lib/log_switch.rb,
lib/log_switch/version.rb

Overview

LogSwitch allows for extending a class/module with a logger and, most importantly, allows for turning off logging programmatically. See the README.rdoc for more info.

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Constant Summary collapse

VERSION =
'1.0.0'

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/log_switch.rb', line 8

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

.loggerObject

Defaults to a Logger writing to STDOUT.


23
24
25
# File 'lib/log_switch.rb', line 23

def self.logger
  @logger ||= ::Logger.new STDOUT
end

.logger=(new_logger) ⇒ Object


27
28
29
# File 'lib/log_switch.rb', line 27

def self.logger=(new_logger)
  @logger = new_logger
end

.reset_config!Object

Sets back to defaults.


32
33
34
35
36
37
38
39
# File 'lib/log_switch.rb', line 32

def self.reset_config!
  self.logger = ::Logger.new STDOUT

  @includers.each do |klass|
    klass.logging_enabled = false
    klass.log_class_name = true
  end
end