Class: Rundock::Logger::Formatter
Instance Attribute Summary collapse
-
#buffer ⇒ Object
Returns the value of attribute buffer.
-
#color(code) ⇒ Object
Returns the value of attribute color.
-
#colored ⇒ Object
Returns the value of attribute colored.
-
#indent_depth ⇒ Object
Returns the value of attribute indent_depth.
-
#onrec ⇒ Object
Returns the value of attribute onrec.
-
#show_header ⇒ Object
Returns the value of attribute show_header.
Instance Method Summary collapse
- #add_indent ⇒ Object
- #call(severity, datetime, progname, msg) ⇒ Object
- #flush ⇒ Object
- #indent ⇒ Object
-
#initialize(*args) ⇒ Formatter
constructor
A new instance of Formatter.
- #reduce_indent ⇒ Object
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
#buffer ⇒ Object
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 |
#colored ⇒ Object
Returns the value of attribute colored.
24 25 26 |
# File 'lib/rundock/logger.rb', line 24 def colored @colored end |
#indent_depth ⇒ Object
Returns the value of attribute indent_depth.
25 26 27 |
# File 'lib/rundock/logger.rb', line 25 def indent_depth @indent_depth end |
#onrec ⇒ Object
Returns the value of attribute onrec.
28 29 30 |
# File 'lib/rundock/logger.rb', line 28 def onrec @onrec end |
#show_header ⇒ Object
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_indent ⇒ Object
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 |
#flush ⇒ Object
76 77 78 79 80 |
# File 'lib/rundock/logger.rb', line 76 def flush ret = @buffer.dup @buffer.clear ret end |
#indent ⇒ Object
53 54 55 56 57 58 |
# File 'lib/rundock/logger.rb', line 53 def indent add_indent yield ensure reduce_indent end |
#reduce_indent ⇒ Object
64 65 66 |
# File 'lib/rundock/logger.rb', line 64 def reduce_indent @indent_depth -= 1 if @indent_depth > 0 end |