gelf 1.1.0.beta2 → 1.1.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/gelf.gemspec +2 -2
- data/lib/gelf/notifier.rb +17 -2
- data/test/test_notifier.rb +30 -0
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.0.
|
1
|
+
1.1.0.beta3
|
data/gelf.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{gelf}
|
8
|
-
s.version = "1.1.0.
|
8
|
+
s.version = "1.1.0.beta3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Alexey Palazhchenko", "Lennart Koopmann"]
|
12
|
-
s.date = %q{2010-11-
|
12
|
+
s.date = %q{2010-11-26}
|
13
13
|
s.description = %q{Suports plain-text, GELF messages and exceptions.}
|
14
14
|
s.email = %q{lennart@socketfeed.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/gelf/notifier.rb
CHANGED
@@ -6,13 +6,15 @@ module GELF
|
|
6
6
|
attr_accessor :last_chunk_id
|
7
7
|
end
|
8
8
|
|
9
|
-
attr_accessor :host, :port, :default_options
|
9
|
+
attr_accessor :host, :port, :default_options, :enabled
|
10
10
|
attr_reader :max_chunk_size, :level
|
11
11
|
|
12
12
|
# +host+ and +port+ are host/ip and port of graylog2-server.
|
13
13
|
# +max_size+ is passed to max_chunk_size=.
|
14
14
|
# +default_options+ is used in notify!
|
15
15
|
def initialize(host = 'localhost', port = 12201, max_size = 'WAN', default_options = {})
|
16
|
+
@enabled = true
|
17
|
+
|
16
18
|
self.level = GELF::DEBUG
|
17
19
|
|
18
20
|
self.host, self.port, self.max_chunk_size = host, port, max_size
|
@@ -40,7 +42,19 @@ module GELF
|
|
40
42
|
end
|
41
43
|
|
42
44
|
def level=(new_level)
|
43
|
-
@level = new_level
|
45
|
+
@level = if new_level.is_a?(Fixnum)
|
46
|
+
new_level
|
47
|
+
else
|
48
|
+
GELF.const_get(new_level.to_s.upcase)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def disable
|
53
|
+
@enabled = false
|
54
|
+
end
|
55
|
+
|
56
|
+
def enable
|
57
|
+
@enabled = true
|
44
58
|
end
|
45
59
|
|
46
60
|
# Same as notify!, but rescues all exceptions (including +ArgumentError+)
|
@@ -79,6 +93,7 @@ module GELF
|
|
79
93
|
end
|
80
94
|
|
81
95
|
def notify_with_level!(message_level, *args)
|
96
|
+
return unless @enabled
|
82
97
|
extract_hash(*args)
|
83
98
|
@hash['level'] = message_level unless message_level.nil?
|
84
99
|
if @hash['level'] >= level
|
data/test/test_notifier.rb
CHANGED
@@ -125,6 +125,13 @@ class TestNotifier < Test::Unit::TestCase
|
|
125
125
|
@notifier.level = GELF::WARN
|
126
126
|
end
|
127
127
|
|
128
|
+
['debug', 'DEBUG', :debug].each do |l|
|
129
|
+
should "allow to set threshold as #{l.inspect}" do
|
130
|
+
@notifier.level = l
|
131
|
+
assert_equal GELF::DEBUG, @notifier.level
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
128
135
|
should "not send notifications with level below threshold" do
|
129
136
|
@sender.expects(:send_datagrams).never
|
130
137
|
@notifier.notify!(HASH.merge('level' => GELF::DEBUG))
|
@@ -136,6 +143,29 @@ class TestNotifier < Test::Unit::TestCase
|
|
136
143
|
end
|
137
144
|
end
|
138
145
|
|
146
|
+
context "when disabled" do
|
147
|
+
setup do
|
148
|
+
@notifier.disable
|
149
|
+
end
|
150
|
+
|
151
|
+
should "not send datagrams" do
|
152
|
+
@sender.expects(:send_datagrams).never
|
153
|
+
@notifier.expects(:extract_hash).never
|
154
|
+
@notifier.notify!(HASH)
|
155
|
+
end
|
156
|
+
|
157
|
+
context "and enabled again" do
|
158
|
+
setup do
|
159
|
+
@notifier.enable
|
160
|
+
end
|
161
|
+
|
162
|
+
should "send datagrams" do
|
163
|
+
@sender.expects(:send_datagrams)
|
164
|
+
@notifier.notify!(HASH)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
139
169
|
should "pass valid data to sender" do
|
140
170
|
@sender.expects(:send_datagrams).with do |datagrams|
|
141
171
|
datagrams.is_a?(Array) && datagrams[0].is_a?(String)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gelf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: -
|
4
|
+
hash: -1848230061
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
9
|
- 0
|
10
|
-
-
|
11
|
-
version: 1.1.0.
|
10
|
+
- beta3
|
11
|
+
version: 1.1.0.beta3
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Alexey Palazhchenko
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-11-
|
20
|
+
date: 2010-11-26 00:00:00 +03:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|