Class: Lumberjack::EcsDevice

Inherits:
JsonDevice
  • Object
show all
Defined in:
lib/lumberjack_ecs_device.rb

Overview

This Lumberjack device logs output to another device as JSON formatted text that maps fields to the standard ECS JSON format.

See www.elastic.co/guide/en/ecs/current/ecs-field-reference.html

Defined Under Namespace

Modules: ExceptionHash Classes: DurationFormatter, EcsTagsFormatter, MessageExceptionFormatter

Constant Summary collapse

ECS_TIMESTAMP_FORMAT =
"%Y-%m-%dT%H:%M:%S.%6NZ"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream_or_device, backtrace_cleaner: nil, max_message_length: nil, datetime_format: ECS_TIMESTAMP_FORMAT) ⇒ EcsDevice

Returns a new instance of EcsDevice.



141
142
143
144
145
146
# File 'lib/lumberjack_ecs_device.rb', line 141

def initialize(stream_or_device, backtrace_cleaner: nil, max_message_length: nil, datetime_format: ECS_TIMESTAMP_FORMAT)
  super(stream_or_device, mapping: ecs_mapping, datetime_format: datetime_format)
  self.backtrace_cleaner = backtrace_cleaner
  self.max_message_length = max_message_length
  @utc_timestamps = !!datetime_format.match(/[^%]Z/)
end

Instance Attribute Details

#backtrace_cleanerObject

You can specify a backtrace cleaner that will be called with exception backtraces before they are added to the payload. You can use this to remove superfluous lines, compress line length, etc. One use for it is to keep stack traces clean and prevent them from overflowing the limit on the payload size for an individual log entry.



135
136
137
# File 'lib/lumberjack_ecs_device.rb', line 135

def backtrace_cleaner
  @backtrace_cleaner
end

#max_message_lengthObject

You can specify a limit on the message size. Messages over this size will be split into multiple log entries to prevent overflowing the limit on message size which makes the log entries unparseable.



139
140
141
# File 'lib/lumberjack_ecs_device.rb', line 139

def max_message_length
  @max_message_length
end

Instance Method Details

#entry_as_json(entry) ⇒ Object



148
149
150
151
152
153
154
155
156
# File 'lib/lumberjack_ecs_device.rb', line 148

def entry_as_json(entry)
  original_time = entry.time
  begin
    entry.time = entry.time.utc if @utc_timestamps && !entry.time.utc?
    super
  ensure
    entry.time = original_time
  end
end