Class: Loggun::Formatter
- Inherits:
-
Object
- Object
- Loggun::Formatter
- Defined in:
- lib/loggun/formatter.rb
Constant Summary collapse
- DEFAULT_VALUE =
'-'.freeze
Instance Method Summary collapse
- #call(severity, time, _program_name, message, loggun_type: nil) ⇒ Object
- #clear_tags! ⇒ Object
- #current_tags ⇒ Object
- #pop_tags(size = 1) ⇒ Object
- #push_tags(*tags) ⇒ Object
- #tagged(*tags) ⇒ Object
- #tags_text ⇒ Object
Instance Method Details
#call(severity, time, _program_name, message, loggun_type: nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/loggun/formatter.rb', line 8 def call(severity, time, _program_name, , loggun_type: nil) data = Hash.new(DEFAULT_VALUE) time = time.utc if config.force_utc (data, ) data[:type] = loggun_type || Loggun.type || DEFAULT_VALUE.dup data[:timestamp] = time.iso8601(config.) data[:time] = data[:timestamp] if config.log_format == :plain data[:severity] = severity&.to_s || 'INFO' data[:pid] = Process.pid data[:tags_text] = data[:transaction_id] = Loggun.transaction_id data[:parent_transaction] = parent_transaction if parent_transaction prepare_to_output(data) end |
#clear_tags! ⇒ Object
45 46 47 |
# File 'lib/loggun/formatter.rb', line 45 def .clear end |
#current_tags ⇒ Object
49 50 51 52 |
# File 'lib/loggun/formatter.rb', line 49 def thread_key = @thread_key ||= "loggun_tagged_logging_tags:#{object_id}" Thread.current[thread_key] ||= [] end |
#pop_tags(size = 1) ⇒ Object
41 42 43 |
# File 'lib/loggun/formatter.rb', line 41 def (size = 1) .pop size end |
#push_tags(*tags) ⇒ Object
35 36 37 38 39 |
# File 'lib/loggun/formatter.rb', line 35 def (*) .flatten.reject(&:blank?).tap do || .concat end end |
#tagged(*tags) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/loggun/formatter.rb', line 28 def tagged(*) = (*) yield self ensure (.size) end |
#tags_text ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/loggun/formatter.rb', line 54 def = if .one? "[#{[0]}] " elsif .any? .collect { |tag| "[#{tag}] " }.join end end |