Class: SemanticLogger::Formatters::SyslogCee

Inherits:
Raw
  • Object
show all
Includes:
SyslogHeader
Defined in:
lib/semantic_logger/formatters/syslog_cee.rb

Constant Summary

Constants included from SyslogHeader

SemanticLogger::Formatters::SyslogHeader::DEFAULT_HOSTNAME, SemanticLogger::Formatters::SyslogHeader::DEFAULT_TAG, SemanticLogger::Formatters::SyslogHeader::MAX_TAG_SIZE

Instance Attribute Summary collapse

Attributes inherited from Raw

#hash, #time_key

Attributes inherited from Base

#filter, #instance_named_tags, #instance_tags, #name

Instance Method Summary collapse

Methods inherited from Raw

#application, #duration, #environment, #exception, #file_name_and_line, #host, #level, #message, #metric, #name, #named_tags, #payload, #pid, #tags, #thread_name

Methods inherited from Base

#backtrace, #benchmark, #fast_tag, #level, #level=, #log, #measure, #named_tags, #pop_tags, #push_tags, #should_log?, #silence, #tagged, #tags, #with_level

Constructor Details

#initialize(facility: SemanticLogger::Formatters::Syslog::LOG_USER, level_map: SemanticLogger::Formatters::Syslog::LevelMap.new, max_size: SemanticLogger::Formatters::Syslog::DEFAULT_MAX_SIZE, **args) ⇒ SyslogCee

CEE JSON Syslog format Untested prototype code. Based on documentation only. If this works for you, please let us know by opening an issue.

Parameters:

facility: [Integer]
One of the ::Syslog::LOG_* facility constants, for example ::Syslog::LOG_LOCAL0.
Default: SemanticLogger::Formatters::Syslog::LOG_USER

level_map: [Hash | SemanticLogger::Formatters::Syslog::LevelMap]
Supply a custom map of SemanticLogger levels to syslog levels.

max_size: [Integer]
Maximum size of each syslog packet, in bytes.
Default: SemanticLogger::Formatters::Syslog::DEFAULT_MAX_SIZE (1024)

Any other options are those of SemanticLogger::Formatters::Raw, such as `log_host` or
`log_exception_details`. Its time options (`time_format`, `time_key`, and `precision`)
have no effect, since the time is in the header of the syslog packet.

Example:

# Log via udp to a remote syslog server on host: `server1` and port `8514`, using the CEE format.
SemanticLogger.add_appender(appender: :syslog, formatter: :syslog_cee, url: 'udp://server1:8514')


32
33
34
35
36
37
38
39
40
# File 'lib/semantic_logger/formatters/syslog_cee.rb', line 32

def initialize(facility: SemanticLogger::Formatters::Syslog::LOG_USER, level_map: SemanticLogger::Formatters::Syslog::LevelMap.new,
               max_size: SemanticLogger::Formatters::Syslog::DEFAULT_MAX_SIZE, **args)
  SemanticLogger::Formatters::Syslog.require_syslog_protocol

  self.facility  = facility
  self.level_map = level_map
  @max_size      = max_size
  super(**args)
end

Instance Attribute Details

#facility ⇒ Object

Returns the value of attribute facility.



7
8
9
# File 'lib/semantic_logger/formatters/syslog_cee.rb', line 7

def facility
  @facility
end

#level_map ⇒ Object

Returns the value of attribute level_map.



7
8
9
# File 'lib/semantic_logger/formatters/syslog_cee.rb', line 7

def level_map
  @level_map
end

#max_size ⇒ Object

Returns the value of attribute max_size.



6
7
8
# File 'lib/semantic_logger/formatters/syslog_cee.rb', line 6

def max_size
  @max_size
end

Instance Method Details

#call(log, logger) ⇒ Object



59
60
61
62
# File 'lib/semantic_logger/formatters/syslog_cee.rb', line 59

def call(log, logger)
  hash = super
  create_syslog_packet("@cee: #{Utils.to_json(hash)}")
end

#time ⇒ Object

Time is part of the syslog packet and is not included in the formatted message.



56
57
# File 'lib/semantic_logger/formatters/syslog_cee.rb', line 56

def time
end