Class: Binnacle::Logging::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/binnacle/logging/formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Formatter

Returns a new instance of Formatter.



6
7
8
# File 'lib/binnacle/logging/formatter.rb', line 6

def initialize(client)
  @client = client
end

Instance Method Details

#assets_log_prefixObject



56
57
58
# File 'lib/binnacle/logging/formatter.rb', line 56

def assets_log_prefix
  @assets_log_prefix ||= "Started GET \"#{Rails.application.config.assets.prefix}" if defined?(Rails)
end

#call(severity, datetime, progname, msg) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/binnacle/logging/formatter.rb', line 10

def call(severity, datetime, progname, msg)
  unless assets_log_prefix && msg.start_with?(assets_log_prefix)
    session_id, client_id = @client.session_and_client_ids

    event = Binnacle::Event.new()

    logging_tags = current_tags.dup
    if progname
      event.configure_from_logging_progname(progname, @client.logging_channel_id, client_id, session_id, severity, nil, datetime, [], { message: msg })
    elsif defined?(ActiveSupport::TaggedLogging) && logging_tags && !logging_tags.empty? && logging_tags.size > 2
      logging_tags.shift(2)
      event_name = logging_tags.shift
      event.configure_from_logging_progname(event_name, @client.logging_channel_id, client_id, session_id, severity, nil, datetime, logging_tags, { message: msg })
    else
      event.configure(@client.logging_channel_id, 'log', client_id, session_id, severity, nil, datetime, [], { message: msg })
    end

    event
  end
end

#clear_tags!Object



48
49
50
# File 'lib/binnacle/logging/formatter.rb', line 48

def clear_tags!
  current_tags.clear
end

#current_tagsObject



52
53
54
# File 'lib/binnacle/logging/formatter.rb', line 52

def current_tags
  Thread.current[:activesupport_tagged_logging_tags] ||= []
end

#pop_tags(size = 1) ⇒ Object



44
45
46
# File 'lib/binnacle/logging/formatter.rb', line 44

def pop_tags(size = 1)
  current_tags.pop size
end

#push_tags(*tags) ⇒ Object



38
39
40
41
42
# File 'lib/binnacle/logging/formatter.rb', line 38

def push_tags(*tags)
  tags.flatten.reject(&:blank?).tap do |new_tags|
    current_tags.concat new_tags
  end
end

#tagged(*tags) ⇒ Object



31
32
33
34
35
36
# File 'lib/binnacle/logging/formatter.rb', line 31

def tagged(*tags)
  new_tags = push_tags(*tags)
  yield self
ensure
  pop_tags(new_tags.size)
end