Module: DefaultLogging

Defined in:
lib/default_logging.rb

Overview

Very simple wrapper around TwP’s Logging framework to provide sensible default behaviour. Specifically:

  • Checks for a configuration file in /etc/log_config.rb by default. This can be overriden by overriding the log_config method in the extended class.

  • Logs to file output.log in app root direction if no config is found.

  • Defines a log method (with default logger) on the class that is extended

Constant Summary collapse

DEFAULT_LOG_CONFIG =
"/etc/log_config.rb"

Instance Method Summary collapse

Instance Method Details

#logObject

Return the logger for this class



19
20
21
22
23
24
25
26
27
28
# File 'lib/default_logging.rb', line 19

def log
  return @logger unless @logger.nil?
  @logger = Logging.logger[self]
  if File.exists?("#{self.log_config}")
    require self.log_config
  else
    @logger.add_appenders(Logging.appenders.file('output.log'))
  end
  @logger
end

#log_configObject

Override to specify a different config file



14
15
16
# File 'lib/default_logging.rb', line 14

def log_config
  DEFAULT_LOG_CONFIG
end