Class: Rundock::Logger::Formatter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Formatter

Returns a new instance of Formatter.



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

def initialize(*args)
  super
  @indent_depth = 0
end

Instance Attribute Details

#color(code) ⇒ Object

Returns the value of attribute color.



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

def color
  @color
end

#coloredObject

Returns the value of attribute colored.



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

def colored
  @colored
end

#indent_depthObject

Returns the value of attribute indent_depth.



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

def indent_depth
  @indent_depth
end

#show_headerObject

Returns the value of attribute show_header.



11
12
13
# File 'lib/rundock/logger.rb', line 11

def show_header
  @show_header
end

Instance Method Details

#add_indentObject



39
40
41
# File 'lib/rundock/logger.rb', line 39

def add_indent
  @indent_depth += 1
end

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



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rundock/logger.rb', line 18

def call(severity, datetime, progname, msg)
  if @show_header
    out = "[\%5s:] %s%s\n" % [severity, ' ' * 2 * indent_depth, msg2str(msg)]
  else
    out = "%s\n" % [msg2str(msg)]
  end

  if colored
    colorize(out, severity)
  else
    out
  end
end

#indentObject



32
33
34
35
36
37
# File 'lib/rundock/logger.rb', line 32

def indent
  add_indent
  yield
ensure
  reduce_indent
end

#reduce_indentObject



43
44
45
# File 'lib/rundock/logger.rb', line 43

def reduce_indent
  @indent_depth -= 1 if @indent_depth > 0
end