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!
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/gelf/notifier.rb', line 33 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.['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.
27 28 29 |
# File 'lib/gelf/notifier.rb', line 27 def collect_file_and_line @collect_file_and_line end |
#default_options ⇒ Object
Returns the value of attribute default_options.
28 29 30 |
# File 'lib/gelf/notifier.rb', line 28 def @default_options end |
#enabled ⇒ Object
Returns the value of attribute enabled.
27 28 29 |
# File 'lib/gelf/notifier.rb', line 27 def enabled @enabled end |
#level ⇒ Object
Returns the value of attribute level.
28 29 30 |
# File 'lib/gelf/notifier.rb', line 28 def level @level end |
#level_mapping ⇒ Object
Returns the value of attribute level_mapping.
28 29 30 |
# File 'lib/gelf/notifier.rb', line 28 def level_mapping @level_mapping end |
#max_chunk_size ⇒ Object
Returns the value of attribute max_chunk_size.
28 29 30 |
# File 'lib/gelf/notifier.rb', line 28 def max_chunk_size @max_chunk_size end |
#rescue_network_errors ⇒ Object
Returns the value of attribute rescue_network_errors.
27 28 29 |
# File 'lib/gelf/notifier.rb', line 27 def rescue_network_errors @rescue_network_errors end |
Instance Method Details
#addresses ⇒ Object
Get a list of receivers.
notifier.addresses # => [['localhost', 12201], ['localhost', 12202]]
54 55 56 |
# File 'lib/gelf/notifier.rb', line 54 def addresses @sender.addresses end |
#addresses=(addrs) ⇒ Object
Set a list of receivers.
notifier.addresses = [['localhost', 12201], ['localhost', 12202]]
60 61 62 |
# File 'lib/gelf/notifier.rb', line 60 def addresses=(addrs) @sender.addresses = addrs end |
#close ⇒ Object
Closes sender
111 112 113 |
# File 'lib/gelf/notifier.rb', line 111 def close @sender.close end |
#disable ⇒ Object
102 103 104 |
# File 'lib/gelf/notifier.rb', line 102 def disable @enabled = false end |
#enable ⇒ Object
106 107 108 |
# File 'lib/gelf/notifier.rb', line 106 def enable @enabled = true end |
#notify(*args) ⇒ Object
Same as notify!, but rescues all exceptions (including ArgumentError
) and sends them instead.
117 118 119 |
# File 'lib/gelf/notifier.rb', line 117 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.
131 132 133 |
# File 'lib/gelf/notifier.rb', line 131 def notify!(*args) notify_with_level!(nil, *args) end |