Class: Intranet::Logger

Inherits:
WEBrick::BasicLog
  • Object
show all
Defined in:
lib/intranet/logger.rb

Overview

The default logger for the Intranet. It is based on WEBrick::BasicLog but adds timestamp and colors to the messages.

Instance Method Summary collapse

Constructor Details

#initialize(level = INFO) ⇒ Logger

Initializes a new logger for $stderr that outputs messages at level or higher. level can be modified later (attribute accessor).

Parameters:

  • level (defaults to: INFO)

    The initial log level.



21
22
23
# File 'lib/intranet/logger.rb', line 21

def initialize(level = INFO)
  super($stderr, level)
end

Instance Method Details

#<<(obj) ⇒ Object

Logs an object that responds to to_s at level INFO.

Parameters:

  • obj (Object)

    The object to log.



34
35
36
# File 'lib/intranet/logger.rb', line 34

def <<(obj)
  info(obj.to_s.chomp)
end

#log(level, msg) ⇒ Object

Logs a message at a given level if it is above the current log level.

Parameters:

  • level

    The level of the message

  • msg (String)

    The message



28
29
30
# File 'lib/intranet/logger.rb', line 28

def log(level, msg)
  super(level, "#{COLOR[level]}#{Time.now.strftime('[%Y-%m-%d %H:%M:%S]')} #{msg}\033[0m")
end