Class: Semlogr::Sinks::ColoredConsole
- Inherits:
-
Object
- Object
- Semlogr::Sinks::ColoredConsole
- Defined in:
- lib/semlogr/sinks/colored_console.rb
Constant Summary collapse
- DEFAULT_TEMPLATE =
"[{timestamp}] {severity}: {message}\n{error}"
- LOG_SEVERITY_COLORS =
{ LogSeverity::DEBUG => :white, LogSeverity::INFO => :white, LogSeverity::WARN => :yellow, LogSeverity::ERROR => :red, LogSeverity::FATAL => :red }.freeze
- COLOR_CODES =
{ white: 37, yellow: 33, red: 31, blue: 34 }.freeze
Instance Method Summary collapse
- #emit(log_event) ⇒ Object
-
#initialize(template: DEFAULT_TEMPLATE) ⇒ ColoredConsole
constructor
A new instance of ColoredConsole.
Constructor Details
#initialize(template: DEFAULT_TEMPLATE) ⇒ ColoredConsole
Returns a new instance of ColoredConsole.
26 27 28 |
# File 'lib/semlogr/sinks/colored_console.rb', line 26 def initialize(template: DEFAULT_TEMPLATE) @template = Templates::Parser.parse(template) end |
Instance Method Details
#emit(log_event) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/semlogr/sinks/colored_console.rb', line 30 def emit(log_event) output = +'' output_properties = Properties::OutputProperties.create(log_event) @template.tokens.each do |token| case token when Templates::PropertyToken render_property_token(output, token, log_event, output_properties) else token.render(output, output_properties) end end STDOUT.write(output) end |