Class: Graylog2Rails::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/graylog2-rails/notifier.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Notifier

Returns a new instance of Notifier.



5
6
7
8
9
10
11
12
13
# File 'lib/graylog2-rails/notifier.rb', line 5

def initialize(args = {})
  @gelf = GELF::Notifier.new(Graylog2Rails.gelf_config_options["host"],
                             Graylog2Rails.gelf_config_options["port"],
                             Graylog2Rails.gelf_config_options["max_chunk_size"], {
                               facility: Graylog2Rails.gelf_config_options["facility"],
                               level: args.has_key?("level") ? args["level"] : Graylog2Rails.gelf_config_options["level"],
                               host: Graylog2Rails.gelf_config_options["local_app_name"]
                             })
end

Instance Attribute Details

#gelfObject (readonly)

Returns the value of attribute gelf.



3
4
5
# File 'lib/graylog2-rails/notifier.rb', line 3

def gelf
  @gelf
end

Class Method Details

.notify!(args) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/graylog2-rails/notifier.rb', line 15

def self.notify! args
  @notifier ||= new
  timestamp = Time.now.utc
  Rails.logger.tagged("GRAYLOG") do
    Rails.logger.info "[#{timestamp.to_datetime}] #{args.inspect}"
  end
  args.merge!({timestamp: timestamp.to_f})
  @notifier.gelf.notify! args unless Rails.env.development?
end