Class: GELF::Notifier
- Inherits:
-
Object
- Object
- GELF::Notifier
- Defined in:
- lib/gelf/notifier.rb
Overview
Graylog2 notifier.
Direct Known Subclasses
Constant Summary collapse
- MAX_CHUNKS =
Maximum number of GELF chunks as per GELF spec
128
- MAX_CHUNK_SIZE_WAN =
1420
- MAX_CHUNK_SIZE_LAN =
8154
Instance Attribute Summary collapse
-
#collect_file_and_line ⇒ Object
Returns the value of attribute collect_file_and_line.
-
#default_options ⇒ Object
Returns the value of attribute default_options.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#level ⇒ Object
Returns the value of attribute level.
-
#level_mapping ⇒ Object
Returns the value of attribute level_mapping.
-
#max_chunk_size ⇒ Object
Returns the value of attribute max_chunk_size.
-
#rescue_network_errors ⇒ Object
Returns the value of attribute rescue_network_errors.
Instance Method Summary collapse
-
#addresses ⇒ Object
Get a list of receivers.
-
#addresses=(addrs) ⇒ Object
Set a list of receivers.
-
#close ⇒ Object
Closes sender.
- #disable ⇒ Object
- #enable ⇒ Object
-
#initialize(host = 'localhost', port = 12201, max_size = 'WAN', default_options = {}) ⇒ Notifier
constructor
host
andport
are host/ip and port of graylog2-server. -
#notify(*args) ⇒ Object
Same as notify!, but rescues all exceptions (including
ArgumentError
) and sends them instead. -
#notify!(*args) ⇒ Object
Sends message to Graylog2 server.
Constructor Details
#initialize(host = 'localhost', port = 12201, max_size = 'WAN', default_options = {}) ⇒ Notifier
host
and port
are host/ip and port of graylog2-server. max_size
is passed to max_chunk_size=. default_options
is used in notify!
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gelf/notifier.rb', line 25 def initialize(host = 'localhost', port = 12201, max_size = 'WAN', = {}) @enabled = true @collect_file_and_line = true @random = Random.new self.level = GELF::DEBUG self.max_chunk_size = max_size self.rescue_network_errors = false self. = .dup self.['version'] = SPEC_VERSION self.['host'] ||= Socket.gethostname self.['level'] ||= GELF::UNKNOWN self.['facility'] ||= 'gelf-rb' self.['protocol'] ||= GELF::Protocol::UDP self.level_mapping = :logger @sender = create_sender(host, port) end |
Instance Attribute Details
#collect_file_and_line ⇒ Object
Returns the value of attribute collect_file_and_line.
19 20 21 |
# File 'lib/gelf/notifier.rb', line 19 def collect_file_and_line @collect_file_and_line end |
#default_options ⇒ Object
Returns the value of attribute default_options.
20 21 22 |
# File 'lib/gelf/notifier.rb', line 20 def @default_options end |
#enabled ⇒ Object
Returns the value of attribute enabled.
19 20 21 |
# File 'lib/gelf/notifier.rb', line 19 def enabled @enabled end |
#level ⇒ Object
Returns the value of attribute level.
20 21 22 |
# File 'lib/gelf/notifier.rb', line 20 def level @level end |
#level_mapping ⇒ Object
Returns the value of attribute level_mapping.
20 21 22 |
# File 'lib/gelf/notifier.rb', line 20 def level_mapping @level_mapping end |
#max_chunk_size ⇒ Object
Returns the value of attribute max_chunk_size.
20 21 22 |
# File 'lib/gelf/notifier.rb', line 20 def max_chunk_size @max_chunk_size end |
#rescue_network_errors ⇒ Object
Returns the value of attribute rescue_network_errors.
19 20 21 |
# File 'lib/gelf/notifier.rb', line 19 def rescue_network_errors @rescue_network_errors end |
Instance Method Details
#addresses ⇒ Object
Get a list of receivers.
notifier.addresses # => [['localhost', 12201], ['localhost', 12202]]
47 48 49 |
# File 'lib/gelf/notifier.rb', line 47 def addresses @sender.addresses end |
#addresses=(addrs) ⇒ Object
Set a list of receivers.
notifier.addresses = [['localhost', 12201], ['localhost', 12202]]
53 54 55 |
# File 'lib/gelf/notifier.rb', line 53 def addresses=(addrs) @sender.addresses = addrs end |
#close ⇒ Object
Closes sender
104 105 106 |
# File 'lib/gelf/notifier.rb', line 104 def close @sender.close end |
#disable ⇒ Object
95 96 97 |
# File 'lib/gelf/notifier.rb', line 95 def disable @enabled = false end |
#enable ⇒ Object
99 100 101 |
# File 'lib/gelf/notifier.rb', line 99 def enable @enabled = true end |
#notify(*args) ⇒ Object
Same as notify!, but rescues all exceptions (including ArgumentError
) and sends them instead.
110 111 112 |
# File 'lib/gelf/notifier.rb', line 110 def notify(*args) notify_with_level(nil, *args) end |
#notify!(*args) ⇒ Object
Sends message to Graylog2 server. args
can be:
-
hash-like object (any object which responds to
to_hash
, includingHash
instance):notify!(:short_message => 'All your rebase are belong to us', :user => 'AlekSi')
-
exception with optional hash-like object:
notify!(SecurityError.new('ALARM!'), :trespasser => 'AlekSi')
-
string-like object (anything which responds to
to_s
) with optional hash-like object:notify!('Plain olde text message', :scribe => 'AlekSi')
Resulted fields are merged with default_options
, the latter will never overwrite the former. This method will raise ArgumentError
if arguments are wrong. Consider using notify instead.
124 125 126 |
# File 'lib/gelf/notifier.rb', line 124 def notify!(*args) notify_with_level!(nil, *args) end |