Class: Lookout::Rack::Utils::Log

Inherits:
Object
  • Object
show all
Includes:
Log4r, Singleton
Defined in:
lib/lookout/rack/utils/log.rb

Overview

Logging. Logs to log/<project_name>.log with the format:

[Log Level]: [Timestamp (ISO-8601)]: [File:linenum]: [Log Message]

Use through the helper:

log.warn 'This is my log message'

Defined Under Namespace

Classes: LookoutFormatter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLog

Returns a new instance of Log.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/lookout/rack/utils/log.rb', line 91

def initialize
  logger_name = configatron.project_name.to_s.gsub(/\s*/, '_')
  if logger_name.nil? || logger_name.empty?
    logger_name = 'no_name_given'
  end

  @logger = Logger.new(logger_name)

  if configatron.logging.enabled
    index = Log4r::LNAMES.index(configatron.logging.level)
    # if logger.level is not in LNAMES an exception will be thrown
    @logger.level = index unless index.nil?
  else
    @logger.level = Log4r::OFF
  end

  @outputter = build_outputter(logger_name)
  @logger.trace = true
  @outputter.formatter = LookoutFormatter
  @logger.outputters = @outputter
end

Instance Attribute Details

#outputterObject (readonly)

Returns the value of attribute outputter.



89
90
91
# File 'lib/lookout/rack/utils/log.rb', line 89

def outputter
  @outputter
end