class Semlogr::Formatters::TextFormatter

Constants

DEFAULT_TEMPLATE

Public Class Methods

new(template: DEFAULT_TEMPLATE) click to toggle source
# File lib/semlogr/formatters/text_formatter.rb, line 12
def initialize(template: DEFAULT_TEMPLATE)
  @template = Templates::Parser.parse(template)
end

Public Instance Methods

format(log_event) click to toggle source
# File lib/semlogr/formatters/text_formatter.rb, line 16
def format(log_event)
  output = +''
  output_properties = Properties::OutputProperties.create(log_event)

  @template.tokens.each do |token|
    case token
    when Templates::PropertyToken
      if token.property_name == :message
        log_event.render(output)
      elsif output_properties[token.property_name]
        token.render(output, output_properties)
      end
    else
      token.render(output, output_properties)
    end
  end

  output
end