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.
-
#date_header ⇒ Object
Returns the value of attribute date_header.
-
#indent_depth ⇒ Object
Returns the value of attribute indent_depth.
-
#onrec ⇒ Object
Returns the value of attribute onrec.
-
#short_header ⇒ Object
Returns the value of attribute short_header.
-
#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
- #formatted_message(severity, datetime, progname, msg) ⇒ 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.
39 40 41 42 43 |
# File 'lib/rundock/logger.rb', line 39 def initialize(*args) super @indent_depth = 0 @buffer = [] end |
Instance Attribute Details
#buffer ⇒ Object
Returns the value of attribute buffer.
37 38 39 |
# File 'lib/rundock/logger.rb', line 37 def buffer @buffer end |
#color(code) ⇒ Object
Returns the value of attribute color.
32 33 34 |
# File 'lib/rundock/logger.rb', line 32 def color @color end |
#colored ⇒ Object
Returns the value of attribute colored.
30 31 32 |
# File 'lib/rundock/logger.rb', line 30 def colored @colored end |
#date_header ⇒ Object
Returns the value of attribute date_header.
35 36 37 |
# File 'lib/rundock/logger.rb', line 35 def date_header @date_header end |
#indent_depth ⇒ Object
Returns the value of attribute indent_depth.
31 32 33 |
# File 'lib/rundock/logger.rb', line 31 def indent_depth @indent_depth end |
#onrec ⇒ Object
Returns the value of attribute onrec.
36 37 38 |
# File 'lib/rundock/logger.rb', line 36 def onrec @onrec end |
#short_header ⇒ Object
Returns the value of attribute short_header.
34 35 36 |
# File 'lib/rundock/logger.rb', line 34 def short_header @short_header end |
#show_header ⇒ Object
Returns the value of attribute show_header.
33 34 35 |
# File 'lib/rundock/logger.rb', line 33 def show_header @show_header end |
Instance Method Details
#add_indent ⇒ Object
63 64 65 |
# File 'lib/rundock/logger.rb', line 63 def add_indent @indent_depth += 1 end |
#call(severity, datetime, progname, msg) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rundock/logger.rb', line 45 def call(severity, datetime, progname, msg) out = (severity, datetime, progname, msg) @buffer << LogEntity.new(severity, datetime, progname, msg, indent_depth, self) if colored colorize(out, severity) else out end end |
#flush ⇒ Object
79 80 81 82 83 |
# File 'lib/rundock/logger.rb', line 79 def flush ret = @buffer.dup @buffer.clear ret end |
#formatted_message(severity, datetime, progname, msg) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rundock/logger.rb', line 85 def (severity, datetime, progname, msg) if !@show_header out = "%s\n" % [msg2str(msg)] elsif !@date_header out = "%5s: %s%s\n" % [ severity, ' ' * 2 * indent_depth, msg2str(msg)] elsif @short_header out = "%s: %s%s\n" % [severity[0, 1], ' ' * 2 * indent_depth, msg2str(msg)] else out = "[%s] %5s: %s%s\n" % [ datetime.strftime('%Y-%m-%dT%H:%M:%S.%L'), severity, ' ' * 2 * indent_depth, msg2str(msg)] end out end |
#indent ⇒ Object
56 57 58 59 60 61 |
# File 'lib/rundock/logger.rb', line 56 def indent add_indent yield ensure reduce_indent end |
#reduce_indent ⇒ Object
67 68 69 |
# File 'lib/rundock/logger.rb', line 67 def reduce_indent @indent_depth -= 1 if @indent_depth > 0 end |