Module: LogSwitch::ClassMethods

Defined in:
lib/log_switch.rb

Instance Method Summary collapse

Instance Method Details

#before_logObject



105
106
107
# File 'lib/log_switch.rb', line 105

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.

Parameters:

  • block (Proc)

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



101
102
103
# File 'lib/log_switch.rb', line 101

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.



62
63
64
# File 'lib/log_switch.rb', line 62

def default_log_level
  @@default_log_level ||= :debug
end

#default_log_level=(level) ⇒ Object

Parameters:

  • level (Symbol)


67
68
69
# File 'lib/log_switch.rb', line 67

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

#log_class_nameObject



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

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.



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

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.



73
74
75
# File 'lib/log_switch.rb', line 73

def log_class_name?
  log_class_name
end

#loggerObject



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

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

#logger=(new_logger) ⇒ Object



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

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

#logging_enabledObject

Parameters:

  • value (Boolean)


43
44
45
# File 'lib/log_switch.rb', line 43

def logging_enabled
  @@logging_enabled ||= false
end

#logging_enabled=(value) ⇒ Object

Use to turn logging on or off.

Parameters:

  • value (Boolean)


57
58
59
# File 'lib/log_switch.rb', line 57

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

#logging_enabled?Boolean

Tells whether logging is turned on or not.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


50
51
52
# File 'lib/log_switch.rb', line 50

def logging_enabled?
  !!logging_enabled
end