Class: SemanticLoggerJournald::Formatter
- Inherits:
-
SemanticLogger::Formatters::Raw
- Object
- SemanticLogger::Formatters::Raw
- SemanticLoggerJournald::Formatter
- Defined in:
- lib/semantic_logger_journald/formatter.rb
Constant Summary collapse
- LEVEL_MAP =
{ trace: Journald::LOG_DEBUG, debug: Journald::LOG_DEBUG, info: Journald::LOG_INFO, warn: Journald::LOG_WARNING, error: Journald::LOG_ERR, fatal: Journald::LOG_CRIT }.freeze
- KEY_JOIN =
"__"
Instance Method Summary collapse
-
#initialize(flatten_payload: KEY_JOIN, time_format: nil, **args) ⇒ Formatter
constructor
A new instance of Formatter.
- #level ⇒ Object
- #named_tags ⇒ Object
- #payload ⇒ Object
-
#pid ⇒ Object
It’s already logged by journald as _PID.
- #tags ⇒ Object
- #time ⇒ Object
Constructor Details
#initialize(flatten_payload: KEY_JOIN, time_format: nil, **args) ⇒ Formatter
Returns a new instance of Formatter.
14 15 16 17 |
# File 'lib/semantic_logger_journald/formatter.rb', line 14 def initialize(flatten_payload: KEY_JOIN, time_format: nil, **args) @flatten_payload = flatten_payload super(time_format: time_format, **args) end |
Instance Method Details
#level ⇒ Object
19 20 21 |
# File 'lib/semantic_logger_journald/formatter.rb', line 19 def level hash[:priority] = LEVEL_MAP.fetch(log.level) end |
#named_tags ⇒ Object
36 37 38 |
# File 'lib/semantic_logger_journald/formatter.rb', line 36 def hash.merge!(log.) if log.&.any? end |
#payload ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/semantic_logger_journald/formatter.rb', line 40 def payload return if !log.payload || log.payload.empty? payload = log.payload payload = flatten_hash(payload) if flatten_payload? hash.merge!(payload) end |
#pid ⇒ Object
It’s already logged by journald as _PID
28 29 30 |
# File 'lib/semantic_logger_journald/formatter.rb', line 28 def pid nil end |
#tags ⇒ Object
32 33 34 |
# File 'lib/semantic_logger_journald/formatter.rb', line 32 def hash.merge!(log..map { |t| [t, 1] }.to_h) if log.&.any? end |
#time ⇒ Object
23 24 25 |
# File 'lib/semantic_logger_journald/formatter.rb', line 23 def time hash[:syslog_timestamp] = time_format ? format_time(log.time) : format_syslog_time(log.time) end |