Class: StickyElephant::ElephantLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/sticky_elephant/elephant_logger.rb

Constant Summary collapse

EVENT_CHANNELS =
{
  connection: 'sticky_elephant.connections',
  query: 'sticky_elephant.queries',
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ ElephantLogger

Returns a new instance of ElephantLogger.



3
4
5
6
7
8
9
10
11
# File 'lib/sticky_elephant/elephant_logger.rb', line 3

def initialize(configuration)
  @text = Logger.new(configuration.log_path)
  @text.level = configuration.log_level
  @hpfeeds = if configuration.use_hpfeeds?
               new_hpfeeds_connection(configuration)
             else
               null_hpfeeds_connection
             end
end

Instance Method Details

#closeObject



35
36
37
38
# File 'lib/sticky_elephant/elephant_logger.rb', line 35

def close
  text.close
  hpfeeds.close
end

#event(type, payload) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/sticky_elephant/elephant_logger.rb', line 24

def event(type, payload)
  unless EVENT_CHANNELS.keys.include? type
    raise ArgumentError.new("Event type #{type} not in #{EVENT_CHANNELS.keys.join(',')}")
  end
  begin
    hpfeeds.publish(payload, EVENT_CHANNELS.fetch(type))
  rescue => e
    warn("#{e.class} received from hpfeeds: #{e}")
  end
end