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.



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

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

Instance Attribute Details

#bufferObject

Returns the value of attribute buffer.



29
30
31
# File 'lib/rundock/logger.rb', line 29

def buffer
  @buffer
end

#color(code) ⇒ Object

Returns the value of attribute color.



26
27
28
# File 'lib/rundock/logger.rb', line 26

def color
  @color
end

#coloredObject

Returns the value of attribute colored.



24
25
26
# File 'lib/rundock/logger.rb', line 24

def colored
  @colored
end

#indent_depthObject

Returns the value of attribute indent_depth.



25
26
27
# File 'lib/rundock/logger.rb', line 25

def indent_depth
  @indent_depth
end

#onrecObject

Returns the value of attribute onrec.



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

def onrec
  @onrec
end

#show_headerObject

Returns the value of attribute show_header.



27
28
29
# File 'lib/rundock/logger.rb', line 27

def show_header
  @show_header
end

Instance Method Details

#add_indentObject



60
61
62
# File 'lib/rundock/logger.rb', line 60

def add_indent
  @indent_depth += 1
end

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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rundock/logger.rb', line 37

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

  @buffer << LogEntity.new(severity, datetime, progname, msg, indent_depth)

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

#flushObject



76
77
78
79
80
# File 'lib/rundock/logger.rb', line 76

def flush
  ret = @buffer.dup
  @buffer.clear
  ret
end

#indentObject



53
54
55
56
57
58
# File 'lib/rundock/logger.rb', line 53

def indent
  add_indent
  yield
ensure
  reduce_indent
end

#reduce_indentObject



64
65
66
# File 'lib/rundock/logger.rb', line 64

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