Module: LogSwitch::ClassMethods

Defined in:
lib/log_switch.rb

Instance Method Summary collapse

Instance Method Details

#before_logObject



112
113
114
# File 'lib/log_switch.rb', line 112

def before_log
  @@before_block ||= Proc.new do; end
end

#before_log=(block) ⇒ Object

#log calls the block given to this method before it logs every time. This, thus, acts as a hook in the case where you want to make sure some code gets executed before you log a message. Useful for making sure a file exists before logging to it.

TODO: broken -- ||= keeps only the first assignment, and #before_log initialises the slot on first read, so later hooks are silently ignored.

Parameters:

  • block (Proc)

    The block of code to execute before logging a message with #log.



108
109
110
# File 'lib/log_switch.rb', line 108

def before_log=(block)
  @@before_block ||= block
end

#default_log_levelSymbol

Returns The current default log level. Starts off as :debug.

Returns:

  • (Symbol)

    The current default log level. Starts off as :debug.



65
66
67
# File 'lib/log_switch.rb', line 65

def default_log_level
  @@default_log_level ||= :debug
end

#default_log_level=(level) ⇒ Object

Parameters:

  • level (Symbol)


70
71
72
# File 'lib/log_switch.rb', line 70

def default_log_level=(level)
  @@default_log_level = level
end

#log_class_nameObject

TODO: broken -- ||= against a truthy default overwrites a stored false on the next read, so log_class_name = false never sticks.



82
83
84
# File 'lib/log_switch.rb', line 82

def log_class_name
  @@log_class_name ||= true
end

#log_class_name=(value) ⇒ Object

Toggle prepending the class name of the #log caller to the log message.



87
88
89
# File 'lib/log_switch.rb', line 87

def log_class_name=(value)
  @@log_class_name = value
end

#log_class_name?Boolean

Returns Tells whether logging of the class name with the log message is turned on.

Returns:

  • (Boolean)

    Tells whether logging of the class name with the log message is turned on.



76
77
78
# File 'lib/log_switch.rb', line 76

def log_class_name?
  log_class_name
end

#loggerObject



91
92
93
# File 'lib/log_switch.rb', line 91

def logger
  @@logger ||= LogSwitch.logger
end

#logger=(new_logger) ⇒ Object



95
96
97
# File 'lib/log_switch.rb', line 95

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

#logging_enabledObject

Parameters:

  • value (Boolean)


46
47
48
# File 'lib/log_switch.rb', line 46

def logging_enabled
  @@logging_enabled ||= false
end

#logging_enabled=(value) ⇒ Object

Use to turn logging on or off.

Parameters:

  • value (Boolean)


60
61
62
# File 'lib/log_switch.rb', line 60

def logging_enabled=(value)
  @@logging_enabled = value
end

#logging_enabled?Boolean

Tells whether logging is turned on or not.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


53
54
55
# File 'lib/log_switch.rb', line 53

def logging_enabled?
  !!logging_enabled
end