Class: Itamae::Logger::Formatter
- Inherits:
-
Object
- Object
- Itamae::Logger::Formatter
- Defined in:
- lib/itamae/logger.rb
Constant Summary collapse
- INDENT_LENGTH =
2
Instance Attribute Summary collapse
-
#color(code) ⇒ Object
Returns the value of attribute color.
-
#colored ⇒ Object
Returns the value of attribute colored.
-
#depth ⇒ Object
Returns the value of attribute depth.
Instance Method Summary collapse
- #call(severity, datetime, progname, msg) ⇒ Object
- #indent ⇒ Object
-
#initialize(*args) ⇒ Formatter
constructor
A new instance of Formatter.
- #outdent ⇒ Object
- #with_indent ⇒ Object
- #with_indent_if(condition, &block) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Formatter
Returns a new instance of Formatter.
14 15 16 17 18 |
# File 'lib/itamae/logger.rb', line 14 def initialize(*args) super @depth = 0 end |
Instance Attribute Details
#color(code) ⇒ Object
Returns the value of attribute color.
10 11 12 |
# File 'lib/itamae/logger.rb', line 10 def color @color end |
#colored ⇒ Object
Returns the value of attribute colored.
8 9 10 |
# File 'lib/itamae/logger.rb', line 8 def colored @colored end |
#depth ⇒ Object
Returns the value of attribute depth.
9 10 11 |
# File 'lib/itamae/logger.rb', line 9 def depth @depth end |
Instance Method Details
#call(severity, datetime, progname, msg) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/itamae/logger.rb', line 20 def call(severity, datetime, progname, msg) log = "%s : %s%s\n" % ["%5s" % severity, ' ' * INDENT_LENGTH * depth , msg2str(msg)] if colored colorize(log, severity) else log end end |
#indent ⇒ Object
44 45 46 |
# File 'lib/itamae/logger.rb', line 44 def indent @depth += 1 end |
#outdent ⇒ Object
48 49 50 51 |
# File 'lib/itamae/logger.rb', line 48 def outdent @depth -= 1 @depth = 0 if @depth < 0 end |
#with_indent ⇒ Object
29 30 31 32 33 34 |
# File 'lib/itamae/logger.rb', line 29 def with_indent indent yield ensure outdent end |
#with_indent_if(condition, &block) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/itamae/logger.rb', line 36 def with_indent_if(condition, &block) if condition with_indent(&block) else block.call end end |