Class: Rundock::Logger::Formatter
Instance Attribute Summary collapse
-
#buffer ⇒ Object
Returns the value of attribute buffer.
-
#color ⇒ 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.
-
#short_header ⇒ Object
Returns the value of attribute short_header.
-
#show_header ⇒ Object
Returns the value of attribute show_header.
-
#suppress_logging ⇒ Object
Returns the value of attribute suppress_logging.
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.
- #new_color(code) ⇒ Object
- #off_rec ⇒ Object
- #on_rec ⇒ Object
- #rec_lock ⇒ Object
- #rec_unlock ⇒ Object
- #reduce_indent ⇒ Object
- #simple_output(msg) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Formatter
Returns a new instance of Formatter.
39 40 41 42 43 44 45 |
# File 'lib/rundock/logger.rb', line 39 def initialize(*args) super @indent_depth = 0 @buffer = [] @rec = false @lock = false 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 ⇒ 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 |
#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 |
#suppress_logging ⇒ Object
Returns the value of attribute suppress_logging.
36 37 38 |
# File 'lib/rundock/logger.rb', line 36 def suppress_logging @suppress_logging end |
Instance Method Details
#add_indent ⇒ Object
65 66 67 |
# File 'lib/rundock/logger.rb', line 65 def add_indent @indent_depth += 1 end |
#call(severity, datetime, progname, msg) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rundock/logger.rb', line 47 def call(severity, datetime, progname, msg) out = (severity, datetime, progname, msg) @buffer << LogEntity.new(severity, datetime, progname, msg, indent_depth, self) if @rec if colored colorize(out, severity) else out end end |
#flush ⇒ Object
81 82 83 84 85 86 |
# File 'lib/rundock/logger.rb', line 81 def flush return nil if @lock ret = @buffer.dup @buffer.clear ret end |
#formatted_message(severity, datetime, progname, msg) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/rundock/logger.rb', line 108 def (severity, datetime, progname, msg) out = if @suppress_logging elsif !@show_header "%s\n" % [msg2str(msg)] elsif !@date_header "%5s: %s%s\n" % [ severity, ' ' * 2 * indent_depth, msg2str(msg) ] elsif @short_header "%s: %s%s\n" % [severity[0, 1], ' ' * 2 * indent_depth, msg2str(msg)] else "[%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
58 59 60 61 62 63 |
# File 'lib/rundock/logger.rb', line 58 def indent add_indent yield ensure reduce_indent end |
#new_color(code) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/rundock/logger.rb', line 73 def new_color(code) prev_color = @color @color = code yield ensure @color = prev_color end |
#off_rec ⇒ Object
92 93 94 |
# File 'lib/rundock/logger.rb', line 92 def off_rec @rec = false unless @lock end |
#on_rec ⇒ Object
88 89 90 |
# File 'lib/rundock/logger.rb', line 88 def on_rec @rec = true unless @lock end |
#rec_lock ⇒ Object
96 97 98 |
# File 'lib/rundock/logger.rb', line 96 def rec_lock @lock = true end |
#rec_unlock ⇒ Object
100 101 102 |
# File 'lib/rundock/logger.rb', line 100 def rec_unlock @lock = false end |
#reduce_indent ⇒ Object
69 70 71 |
# File 'lib/rundock/logger.rb', line 69 def reduce_indent @indent_depth -= 1 if @indent_depth > 0 end |
#simple_output(msg) ⇒ Object
104 105 106 |
# File 'lib/rundock/logger.rb', line 104 def simple_output(msg) puts msg2str(msg) end |