Class: Logcraft::LogLayout

Inherits:
Logging::Layout
  • Object
show all
Defined in:
lib/logcraft/log_layout.rb

Constant Summary collapse

JSON_FORMATTER =
->(event) { MultiJson.dump(event) + "\n" }.freeze
LOGGING_LEVEL_FORMATTER =
->(level) { Logging::LNAMES[level] }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(global_context = {}, options = {}) ⇒ LogLayout

Returns a new instance of LogLayout.



10
11
12
13
14
# File 'lib/logcraft/log_layout.rb', line 10

def initialize(global_context = {}, options = {})
  @global_context = global_context
  @formatter = options.fetch :formatter, JSON_FORMATTER
  @level_formatter = options.fetch :level_formatter, LOGGING_LEVEL_FORMATTER
end

Instance Method Details

#format(event) ⇒ Object



16
17
18
19
20
21
# File 'lib/logcraft/log_layout.rb', line 16

def format(event)
  log_entry = background_of(event).merge evaluated_global_context,
                                         dynamic_log_context,
                                         message_from(event.data)
  @formatter.call log_entry
end