Class: TidyLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/tidy_logger.rb

Defined Under Namespace

Classes: Formatter

Constant Summary collapse

Error =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ TidyLogger

Returns a new instance of TidyLogger.


4
5
6
7
# File 'lib/tidy_logger.rb', line 4

def initialize(*args)
  super
  @formatter = Formatter.new
end

Instance Method Details

#config(options = :time_and_level) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tidy_logger.rb', line 9

def config(options = :time_and_level)
  case options
  when Symbol
    options = { type: options }
  when Hash
    options[:type] = :time_and_level  if options[:type].nil?
    options[:type] = :title           if options[:title]
  when Proc
    options = { type: options }
  else
    raise Error, "invalid options: #{options.inspect}"
  end

  self.formatter.type             = options[:type]
  self.level                      = options[:level] || Logger::INFO
  self.formatter.datetime_format  = options[:datetime_format] || '%Y-%m-%dT%H:%M:%S'
  self.formatter.title            = options[:title]
  self
end