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.
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
Constructor Details
#initialize(*args) ⇒ Formatter
Returns a new instance of Formatter.
38 39 40 41 42 43 44 |
# File 'lib/rundock/logger.rb', line 38 def initialize(*args) super @indent_depth = 0 @buffer = [] @rec = false @lock = false end |
Instance Attribute Details
#buffer ⇒ Object
Returns the value of attribute buffer.
36 37 38 |
# File 'lib/rundock/logger.rb', line 36 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 |
Instance Method Details
#add_indent ⇒ Object
64 65 66 |
# File 'lib/rundock/logger.rb', line 64 def add_indent @indent_depth += 1 end |
#call(severity, datetime, progname, msg) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rundock/logger.rb', line 46 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
80 81 82 83 84 85 |
# File 'lib/rundock/logger.rb', line 80 def flush return nil if @lock ret = @buffer.dup @buffer.clear ret end |
#formatted_message(severity, datetime, progname, msg) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/rundock/logger.rb', line 103 def (severity, datetime, progname, msg) out = if !@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
57 58 59 60 61 62 |
# File 'lib/rundock/logger.rb', line 57 def indent add_indent yield ensure reduce_indent end |
#new_color(code) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/rundock/logger.rb', line 72 def new_color(code) prev_color = @color @color = code yield ensure @color = prev_color end |
#off_rec ⇒ Object
91 92 93 |
# File 'lib/rundock/logger.rb', line 91 def off_rec @rec = false unless @lock end |
#on_rec ⇒ Object
87 88 89 |
# File 'lib/rundock/logger.rb', line 87 def on_rec @rec = true unless @lock end |
#rec_lock ⇒ Object
95 96 97 |
# File 'lib/rundock/logger.rb', line 95 def rec_lock @lock = true end |
#rec_unlock ⇒ Object
99 100 101 |
# File 'lib/rundock/logger.rb', line 99 def rec_unlock @lock = false end |
#reduce_indent ⇒ Object
68 69 70 |
# File 'lib/rundock/logger.rb', line 68 def reduce_indent @indent_depth -= 1 if @indent_depth > 0 end |