Class: JuanPelota::Logger

Inherits:
Sidekiq::Logging::Pretty
  • Object
show all
Defined in:
lib/juan_pelota/logger.rb

Constant Summary collapse

IGNORABLE_STATUSES =
%w{start done queueing}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#program_nameObject

Returns the value of attribute program_name.



12
13
14
# File 'lib/juan_pelota/logger.rb', line 12

def program_name
  @program_name
end

#raw_message=(value) ⇒ Object

Sets the attribute raw_message

Parameters:

  • value

    the value to set the attribute raw_message to.



12
13
14
# File 'lib/juan_pelota/logger.rb', line 12

def raw_message=(value)
  @raw_message = value
end

#severityObject

Returns the value of attribute severity.



12
13
14
# File 'lib/juan_pelota/logger.rb', line 12

def severity
  @severity
end

#timestampObject

Returns the value of attribute timestamp.



12
13
14
# File 'lib/juan_pelota/logger.rb', line 12

def timestamp
  @timestamp
end

Class Method Details

.pidObject



44
45
46
# File 'lib/juan_pelota/logger.rb', line 44

def self.pid
  ::Process.pid
end

.tidObject



48
49
50
# File 'lib/juan_pelota/logger.rb', line 48

def self.tid
  ::Thread.current.object_id.to_s(36)
end

Instance Method Details

#call(severity, time, program_name, incoming_message) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/juan_pelota/logger.rb', line 17

def call(severity, time, program_name, incoming_message)
  self.severity     = severity
  self.timestamp    = time.utc.iso8601
  self.program_name = program_name
  self.raw_message  = incoming_message

  return if config.filtered_workers.include?(worker_name.to_s) &&
            IGNORABLE_STATUSES.include?(status)

  {
    '@type'      => 'sidekiq',
    '@timestamp' => timestamp,
    '@status'    => status,
    '@severity'  => severity.downcase,
    '@run_time'  => run_time,
    '@message'   => message,
    '@fields'    => {
      pid:          self.class.pid,
      tid:          self.class.tid,
      context:      context,
      program_name: program_name,
      worker:       worker_name,
      arguments:    arguments,
    },
  }.to_json + "\n"
end