Class: Itamae::Logger::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/itamae/logger.rb

Constant Summary collapse

INDENT_LENGTH =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Formatter

Returns a new instance of Formatter


14
15
16
17
18
# File 'lib/itamae/logger.rb', line 14

def initialize(*args)
  super

  @depth = 0
end

Instance Attribute Details

#color(code) ⇒ Object

Returns the value of attribute color


10
11
12
# File 'lib/itamae/logger.rb', line 10

def color
  @color
end

#coloredObject

Returns the value of attribute colored


8
9
10
# File 'lib/itamae/logger.rb', line 8

def colored
  @colored
end

#depthObject

Returns the value of attribute depth


9
10
11
# File 'lib/itamae/logger.rb', line 9

def depth
  @depth
end

Instance Method Details

#call(severity, datetime, progname, msg) ⇒ Object


20
21
22
23
24
25
26
27
# File 'lib/itamae/logger.rb', line 20

def call(severity, datetime, progname, msg)
  log = "%s : %s%s\n" % ["%5s" % severity, ' ' * INDENT_LENGTH * depth , msg2str(msg)]
  if colored
    colorize(log, severity)
  else
    log
  end
end

#indentObject


29
30
31
32
33
34
# File 'lib/itamae/logger.rb', line 29

def indent
  @depth += 1
  yield
ensure
  @depth -= 1
end