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.



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

def initialize(*args)
  super

  @depth = 0
end

Instance Attribute Details

#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



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

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

#indentObject



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

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