gelf 1.1.0.gamma1 → 1.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -1
- data/VERSION +1 -1
- data/gelf.gemspec +4 -4
- data/lib/gelf/logger.rb +2 -2
- data/lib/gelf/notifier.rb +26 -29
- data/lib/gelf/ruby_sender.rb +12 -12
- data/test/test_logger.rb +18 -18
- data/test/test_notifier.rb +63 -45
- metadata +5 -11
data/CHANGELOG
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
* requires graylog2-web-interface version XXXXXXXXXXXX;
|
5
5
|
+ Notifier#default_options;
|
6
6
|
+ severity (level) threshold;
|
7
|
-
+ automatically set '_file', '_line' and '_timestamp'
|
7
|
+
+ automatically set '_file', '_line' and '_timestamp' fields;
|
8
8
|
+ wrappers for GELF::Notifier#notify with severity:
|
9
9
|
+ GELF::Notifier.debug
|
10
10
|
+ GELF::Notifier.info
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.0.
|
1
|
+
1.1.0.rc1
|
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.rc1"
|
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 = ["Aleksey Palazhchenko", "Lennart Koopmann"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-01-08}
|
13
13
|
s.description = %q{Library to send GELF messages to Graylog2 logging server. Supports plain-text, GELF messages and exceptions.}
|
14
14
|
s.email = %q{aleksey.palazhchenko@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -46,11 +46,11 @@ Gem::Specification.new do |s|
|
|
46
46
|
s.summary = %q{Library to send GELF messages to Graylog2 logging server.}
|
47
47
|
s.test_files = [
|
48
48
|
"test/helper.rb",
|
49
|
-
"test/test_deprecations.rb",
|
50
49
|
"test/test_logger.rb",
|
51
50
|
"test/test_notifier.rb",
|
51
|
+
"test/test_severity.rb",
|
52
52
|
"test/test_ruby_sender.rb",
|
53
|
-
"test/
|
53
|
+
"test/test_deprecations.rb"
|
54
54
|
]
|
55
55
|
|
56
56
|
if s.respond_to? :specification_version then
|
data/lib/gelf/logger.rb
CHANGED
@@ -20,7 +20,7 @@ module GELF
|
|
20
20
|
[args[0], nil]
|
21
21
|
end
|
22
22
|
|
23
|
-
hash = {'
|
23
|
+
hash = {'short_message' => message, 'facility' => facility}
|
24
24
|
hash.merge!(self.class.extract_hash_from_exception(message)) if message.is_a?(Exception)
|
25
25
|
notify_with_level(level, hash)
|
26
26
|
end
|
@@ -40,7 +40,7 @@ module GELF
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def <<(message)
|
43
|
-
notify('
|
43
|
+
notify('short_message' => message, 'level' => GELF::UNKNOWN)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
data/lib/gelf/notifier.rb
CHANGED
@@ -19,12 +19,11 @@ module GELF
|
|
19
19
|
|
20
20
|
self.host, self.port, self.max_chunk_size = host, port, max_size
|
21
21
|
|
22
|
-
@default_options = {}
|
23
22
|
self.default_options = default_options
|
24
|
-
self.default_options['
|
25
|
-
self.default_options['
|
26
|
-
self.default_options['
|
27
|
-
self.default_options['
|
23
|
+
self.default_options['version'] = SPEC_VERSION
|
24
|
+
self.default_options['host'] ||= Socket.gethostname
|
25
|
+
self.default_options['level'] ||= GELF::UNKNOWN
|
26
|
+
self.default_options['facility'] ||= 'gelf-rb'
|
28
27
|
|
29
28
|
@sender = RubyUdpSender.new(host, port)
|
30
29
|
end
|
@@ -96,8 +95,8 @@ module GELF
|
|
96
95
|
def notify_with_level!(message_level, *args)
|
97
96
|
return unless @enabled
|
98
97
|
extract_hash(*args)
|
99
|
-
@hash['
|
100
|
-
if @hash['
|
98
|
+
@hash['level'] = message_level unless message_level.nil?
|
99
|
+
if @hash['level'] >= level
|
101
100
|
@sender.send_datagrams(datagrams_from_hash)
|
102
101
|
end
|
103
102
|
end
|
@@ -106,11 +105,11 @@ module GELF
|
|
106
105
|
primary_data = if object.respond_to?(:to_hash)
|
107
106
|
object.to_hash
|
108
107
|
elsif object.is_a?(Exception)
|
109
|
-
args['
|
108
|
+
args['level'] ||= GELF::ERROR
|
110
109
|
self.class.extract_hash_from_exception(object)
|
111
110
|
else
|
112
|
-
args['
|
113
|
-
{ '
|
111
|
+
args['level'] ||= GELF::INFO
|
112
|
+
{ 'short_message' => object.to_s }
|
114
113
|
end
|
115
114
|
|
116
115
|
@hash = default_options.merge(args.merge(primary_data))
|
@@ -124,16 +123,14 @@ module GELF
|
|
124
123
|
|
125
124
|
def self.extract_hash_from_exception(exception)
|
126
125
|
bt = exception.backtrace || ["Backtrace is not available."]
|
127
|
-
{ '
|
126
|
+
{ 'short_message' => "#{exception.class}: #{exception.message}", 'full_message' => "Backtrace:\n" + bt.join("\n") }
|
128
127
|
end
|
129
128
|
|
130
129
|
# Converts Hoptoad-specific keys in +@hash+ to Graylog2-specific.
|
131
130
|
def convert_hoptoad_keys_to_graylog2
|
132
|
-
if @hash['
|
131
|
+
if @hash['short_message'].to_s.empty?
|
133
132
|
if @hash.has_key?('error_class') && @hash.has_key?('error_message')
|
134
|
-
@hash['
|
135
|
-
@hash.delete('error_class')
|
136
|
-
@hash.delete('error_message')
|
133
|
+
@hash['short_message'] = @hash.delete('error_class') + ': ' + @hash.delete('error_message')
|
137
134
|
end
|
138
135
|
end
|
139
136
|
end
|
@@ -147,28 +144,24 @@ module GELF
|
|
147
144
|
frame = stack.shift
|
148
145
|
end while frame.include?(LIB_GELF_PATTERN)
|
149
146
|
match = CALLER_REGEXP.match(frame)
|
150
|
-
@hash['
|
151
|
-
@hash['
|
147
|
+
@hash['file'] = match[1]
|
148
|
+
@hash['line'] = match[2].to_i
|
152
149
|
end
|
153
150
|
|
154
151
|
def set_timestamp
|
155
|
-
@hash['
|
152
|
+
@hash['timestamp'] = Time.now.utc.to_f
|
156
153
|
end
|
157
154
|
|
158
155
|
def check_presence_of_mandatory_attributes
|
159
|
-
%w(
|
156
|
+
%w(version short_message host).each do |attribute|
|
160
157
|
if @hash[attribute].to_s.empty?
|
161
|
-
raise ArgumentError.new("#{attribute} is missing. Options
|
158
|
+
raise ArgumentError.new("#{attribute} is missing. Options version, short_message and host must be set.")
|
162
159
|
end
|
163
160
|
end
|
164
161
|
end
|
165
162
|
|
166
163
|
def datagrams_from_hash
|
167
|
-
|
168
|
-
|
169
|
-
@hash['_level'] = GELF::LEVELS_MAPPING[@hash['_level']]
|
170
|
-
|
171
|
-
data = Zlib::Deflate.deflate(@hash.to_json).bytes
|
164
|
+
data = serialize_hash
|
172
165
|
datagrams = []
|
173
166
|
|
174
167
|
# Maximum total size is 8192 byte for UDP datagram. Split to chunks if bigger. (GELFv2 supports chunking)
|
@@ -177,18 +170,22 @@ module GELF
|
|
177
170
|
msg_id = Digest::MD5.digest("#{Time.now.to_f}-#{id}")[0, 8]
|
178
171
|
num, count = 0, (data.count.to_f / @max_chunk_size).ceil
|
179
172
|
data.each_slice(@max_chunk_size) do |slice|
|
180
|
-
datagrams <<
|
173
|
+
datagrams << "\x1e\x0f" + msg_id + [num, count, *slice].pack('C*')
|
181
174
|
num += 1
|
182
175
|
end
|
183
176
|
else
|
184
|
-
datagrams
|
177
|
+
datagrams << data.to_a.pack('C*')
|
185
178
|
end
|
186
179
|
|
187
180
|
datagrams
|
188
181
|
end
|
189
182
|
|
190
|
-
def
|
191
|
-
|
183
|
+
def serialize_hash
|
184
|
+
raise ArgumentError.new("Hash is empty.") if @hash.nil? || @hash.empty?
|
185
|
+
|
186
|
+
@hash['level'] = GELF::LEVELS_MAPPING[@hash['level']]
|
187
|
+
|
188
|
+
Zlib::Deflate.deflate(@hash.to_json).bytes
|
192
189
|
end
|
193
190
|
|
194
191
|
def stringify_hash_keys
|
data/lib/gelf/ruby_sender.rb
CHANGED
@@ -14,16 +14,16 @@ module GELF
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# Plain Ruby TCP sender.
|
17
|
-
class RubyTcpSender
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
17
|
+
# class RubyTcpSender
|
18
|
+
# def initialize(host, port)
|
19
|
+
# @host, @port = host, port
|
20
|
+
# @socket = TCPSocket.open
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# def send_datagrams(datagrams)
|
24
|
+
# datagrams.each do |datagram|
|
25
|
+
# @socket.send(datagram, 0, @host, @port)
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
# end
|
29
29
|
end
|
data/test/test_logger.rb
CHANGED
@@ -18,7 +18,7 @@ class TestLogger < Test::Unit::TestCase
|
|
18
18
|
should "implement add method with level and message from parameters" do
|
19
19
|
@notifier.expects(:notify_with_level!).with do |level, hash|
|
20
20
|
level == GELF::INFO &&
|
21
|
-
hash['
|
21
|
+
hash['short_message'] == 'Message'
|
22
22
|
end
|
23
23
|
@notifier.add(GELF::INFO, 'Message')
|
24
24
|
end
|
@@ -27,8 +27,8 @@ class TestLogger < Test::Unit::TestCase
|
|
27
27
|
should "implement add method with level and exception from parameters" do
|
28
28
|
@notifier.expects(:notify_with_level!).with do |level, hash|
|
29
29
|
level == GELF::INFO &&
|
30
|
-
hash['
|
31
|
-
hash['
|
30
|
+
hash['short_message'] == 'RuntimeError: Boom!' &&
|
31
|
+
hash['full_message'] =~ /^Backtrace/
|
32
32
|
end
|
33
33
|
@notifier.add(GELF::INFO, RuntimeError.new('Boom!'))
|
34
34
|
end
|
@@ -37,7 +37,7 @@ class TestLogger < Test::Unit::TestCase
|
|
37
37
|
should "implement add method with level from parameter and message from block" do
|
38
38
|
@notifier.expects(:notify_with_level!).with do |level, hash|
|
39
39
|
level == GELF::INFO &&
|
40
|
-
hash['
|
40
|
+
hash['short_message'] == 'Message'
|
41
41
|
end
|
42
42
|
@notifier.add(GELF::INFO) { 'Message' }
|
43
43
|
end
|
@@ -46,8 +46,8 @@ class TestLogger < Test::Unit::TestCase
|
|
46
46
|
should "implement add method with level from parameter and exception from block" do
|
47
47
|
@notifier.expects(:notify_with_level!).with do |level, hash|
|
48
48
|
level == GELF::INFO &&
|
49
|
-
hash['
|
50
|
-
hash['
|
49
|
+
hash['short_message'] == 'RuntimeError: Boom!' &&
|
50
|
+
hash['full_message'] =~ /^Backtrace/
|
51
51
|
end
|
52
52
|
@notifier.add(GELF::INFO) { RuntimeError.new('Boom!') }
|
53
53
|
end
|
@@ -56,8 +56,8 @@ class TestLogger < Test::Unit::TestCase
|
|
56
56
|
should "implement add method with level, message and facility from parameters" do
|
57
57
|
@notifier.expects(:notify_with_level!).with do |level, hash|
|
58
58
|
level == GELF::INFO &&
|
59
|
-
hash['
|
60
|
-
hash['
|
59
|
+
hash['short_message'] == 'Message' &&
|
60
|
+
hash['facility'] == 'Facility'
|
61
61
|
end
|
62
62
|
@notifier.add(GELF::INFO, 'Message', 'Facility')
|
63
63
|
end
|
@@ -66,9 +66,9 @@ class TestLogger < Test::Unit::TestCase
|
|
66
66
|
should "implement add method with level, exception and facility from parameters" do
|
67
67
|
@notifier.expects(:notify_with_level!).with do |level, hash|
|
68
68
|
level == GELF::INFO &&
|
69
|
-
hash['
|
70
|
-
hash['
|
71
|
-
hash['
|
69
|
+
hash['short_message'] == 'RuntimeError: Boom!' &&
|
70
|
+
hash['full_message'] =~ /^Backtrace/ &&
|
71
|
+
hash['facility'] == 'Facility'
|
72
72
|
end
|
73
73
|
@notifier.add(GELF::INFO, RuntimeError.new('Boom!'), 'Facility')
|
74
74
|
end
|
@@ -77,8 +77,8 @@ class TestLogger < Test::Unit::TestCase
|
|
77
77
|
should "implement add method with level and facility from parameters and message from block" do
|
78
78
|
@notifier.expects(:notify_with_level!).with do |level, hash|
|
79
79
|
level == GELF::INFO &&
|
80
|
-
hash['
|
81
|
-
hash['
|
80
|
+
hash['short_message'] == 'Message' &&
|
81
|
+
hash['facility'] == 'Facility'
|
82
82
|
end
|
83
83
|
@notifier.add(GELF::INFO, 'Facility') { 'Message' }
|
84
84
|
end
|
@@ -87,9 +87,9 @@ class TestLogger < Test::Unit::TestCase
|
|
87
87
|
should "implement add method with level and facility from parameters and exception from block" do
|
88
88
|
@notifier.expects(:notify_with_level!).with do |level, hash|
|
89
89
|
level == GELF::INFO &&
|
90
|
-
hash['
|
91
|
-
hash['
|
92
|
-
hash['
|
90
|
+
hash['short_message'] == 'RuntimeError: Boom!' &&
|
91
|
+
hash['full_message'] =~ /^Backtrace/ &&
|
92
|
+
hash['facility'] == 'Facility'
|
93
93
|
end
|
94
94
|
@notifier.add(GELF::INFO, 'Facility') { RuntimeError.new('Boom!') }
|
95
95
|
end
|
@@ -126,8 +126,8 @@ class TestLogger < Test::Unit::TestCase
|
|
126
126
|
|
127
127
|
should "support Notifier#<<" do
|
128
128
|
@notifier.expects(:notify_with_level!).with do |nil_, hash|
|
129
|
-
hash['
|
130
|
-
hash['
|
129
|
+
hash['short_message'] == "Message" &&
|
130
|
+
hash['level'] == GELF::UNKNOWN
|
131
131
|
end
|
132
132
|
@notifier << "Message"
|
133
133
|
end
|
data/test/test_notifier.rb
CHANGED
@@ -7,12 +7,12 @@ class TestNotifier < Test::Unit::TestCase
|
|
7
7
|
Socket.expects(:gethostname).returns('default_hostname')
|
8
8
|
n = GELF::Notifier.new
|
9
9
|
assert_equal ['localhost', 12201, 1420], [n.host, n.port, n.max_chunk_size]
|
10
|
-
assert_equal( { '
|
11
|
-
'
|
10
|
+
assert_equal( { 'version' => '1.0', 'level' => GELF::UNKNOWN,
|
11
|
+
'host' => 'default_hostname', 'facility' => 'gelf-rb' },
|
12
12
|
n.default_options )
|
13
|
-
n.host, n.port, n.max_chunk_size, n.default_options = 'graylog2.org', 7777, :lan, {'
|
13
|
+
n.host, n.port, n.max_chunk_size, n.default_options = 'graylog2.org', 7777, :lan, {'host' => 'grayhost'}
|
14
14
|
assert_equal ['graylog2.org', 7777, 8154], [n.host, n.port, n.max_chunk_size]
|
15
|
-
assert_equal({'
|
15
|
+
assert_equal({'host' => 'grayhost'}, n.default_options)
|
16
16
|
|
17
17
|
n.max_chunk_size = 1337.1
|
18
18
|
assert_equal 1337, n.max_chunk_size
|
@@ -33,108 +33,126 @@ class TestNotifier < Test::Unit::TestCase
|
|
33
33
|
end
|
34
34
|
|
35
35
|
should "work with hash" do
|
36
|
-
hash = @notifier.__send__(:extract_hash, { '
|
37
|
-
assert_equal '1.0', hash['
|
38
|
-
assert_equal 'message', hash['
|
36
|
+
hash = @notifier.__send__(:extract_hash, { 'version' => '1.0', 'short_message' => 'message' })
|
37
|
+
assert_equal '1.0', hash['version']
|
38
|
+
assert_equal 'message', hash['short_message']
|
39
39
|
end
|
40
40
|
|
41
41
|
should "work with any object which responds to #to_hash" do
|
42
42
|
o = Object.new
|
43
|
-
o.expects(:to_hash).returns({ '
|
43
|
+
o.expects(:to_hash).returns({ 'version' => '1.0', 'short_message' => 'message' })
|
44
44
|
hash = @notifier.__send__(:extract_hash, o)
|
45
|
-
assert_equal '1.0', hash['
|
46
|
-
assert_equal 'message', hash['
|
45
|
+
assert_equal '1.0', hash['version']
|
46
|
+
assert_equal 'message', hash['short_message']
|
47
47
|
end
|
48
48
|
|
49
49
|
should "work with exception with backtrace" do
|
50
50
|
e = RuntimeError.new('message')
|
51
51
|
e.set_backtrace(caller)
|
52
52
|
hash = @notifier.__send__(:extract_hash, e)
|
53
|
-
assert_equal 'RuntimeError: message', hash['
|
54
|
-
assert_match /Backtrace/, hash['
|
55
|
-
assert_equal GELF::ERROR, hash['
|
53
|
+
assert_equal 'RuntimeError: message', hash['short_message']
|
54
|
+
assert_match /Backtrace/, hash['full_message']
|
55
|
+
assert_equal GELF::ERROR, hash['level']
|
56
56
|
end
|
57
57
|
|
58
58
|
should "work with exception without backtrace" do
|
59
59
|
e = RuntimeError.new('message')
|
60
60
|
hash = @notifier.__send__(:extract_hash, e)
|
61
|
-
assert_match /Backtrace is not available/, hash['
|
61
|
+
assert_match /Backtrace is not available/, hash['full_message']
|
62
62
|
end
|
63
63
|
|
64
64
|
should "work with exception and hash" do
|
65
|
-
e, h = RuntimeError.new('message'), {'param' => 1, '
|
65
|
+
e, h = RuntimeError.new('message'), {'param' => 1, 'level' => GELF::FATAL, 'short_message' => 'will be hidden by exception'}
|
66
66
|
hash = @notifier.__send__(:extract_hash, e, h)
|
67
|
-
assert_equal 'RuntimeError: message', hash['
|
68
|
-
assert_equal GELF::FATAL, hash['
|
67
|
+
assert_equal 'RuntimeError: message', hash['short_message']
|
68
|
+
assert_equal GELF::FATAL, hash['level']
|
69
69
|
assert_equal 1, hash['param']
|
70
70
|
end
|
71
71
|
|
72
72
|
should "work with plain text" do
|
73
73
|
hash = @notifier.__send__(:extract_hash, 'message')
|
74
|
-
assert_equal 'message', hash['
|
75
|
-
assert_equal GELF::INFO, hash['
|
74
|
+
assert_equal 'message', hash['short_message']
|
75
|
+
assert_equal GELF::INFO, hash['level']
|
76
76
|
end
|
77
77
|
|
78
78
|
should "work with plain text and hash" do
|
79
|
-
hash = @notifier.__send__(:extract_hash, 'message', '
|
80
|
-
assert_equal 'message', hash['
|
81
|
-
assert_equal GELF::WARN, hash['
|
79
|
+
hash = @notifier.__send__(:extract_hash, 'message', 'level' => GELF::WARN)
|
80
|
+
assert_equal 'message', hash['short_message']
|
81
|
+
assert_equal GELF::WARN, hash['level']
|
82
82
|
end
|
83
83
|
|
84
84
|
should "covert hash keys to strings" do
|
85
|
-
hash = @notifier.__send__(:extract_hash, :
|
86
|
-
assert hash.has_key?('
|
87
|
-
assert !hash.has_key?(:
|
85
|
+
hash = @notifier.__send__(:extract_hash, :short_message => :message)
|
86
|
+
assert hash.has_key?('short_message')
|
87
|
+
assert !hash.has_key?(:short_message)
|
88
88
|
end
|
89
89
|
|
90
90
|
should "not overwrite keys on convert" do
|
91
|
-
assert_raise(ArgumentError) { @notifier.__send__(:extract_hash, :
|
91
|
+
assert_raise(ArgumentError) { @notifier.__send__(:extract_hash, :short_message => :message1, 'short_message' => 'message2') }
|
92
92
|
end
|
93
93
|
|
94
94
|
should "use default_options" do
|
95
|
-
@notifier.default_options = {:foo => 'bar', '
|
96
|
-
hash = @notifier.__send__(:extract_hash, { '
|
95
|
+
@notifier.default_options = {:foo => 'bar', 'short_message' => 'will be hidden by explicit argument', 'host' => 'some_host'}
|
96
|
+
hash = @notifier.__send__(:extract_hash, { 'version' => '1.0', 'short_message' => 'message' })
|
97
97
|
assert_equal 'bar', hash['foo']
|
98
|
-
assert_equal 'message', hash['
|
98
|
+
assert_equal 'message', hash['short_message']
|
99
99
|
end
|
100
100
|
|
101
101
|
should "be compatible with HoptoadNotifier" do
|
102
102
|
# https://github.com/thoughtbot/hoptoad_notifier/blob/master/README.rdoc, section Going beyond exceptions
|
103
103
|
hash = @notifier.__send__(:extract_hash, :error_class => 'Class', :error_message => 'Message')
|
104
|
-
assert_equal 'Class: Message', hash['
|
104
|
+
assert_equal 'Class: Message', hash['short_message']
|
105
105
|
end
|
106
106
|
|
107
107
|
should "set file and line" do
|
108
108
|
line = __LINE__
|
109
|
-
hash = @notifier.__send__(:extract_hash, { '
|
110
|
-
assert_match /test_notifier.rb/, hash['
|
111
|
-
assert_equal line + 1, hash['
|
109
|
+
hash = @notifier.__send__(:extract_hash, { 'version' => '1.0', 'short_message' => 'message' })
|
110
|
+
assert_match /test_notifier.rb/, hash['file']
|
111
|
+
assert_equal line + 1, hash['line']
|
112
112
|
end
|
113
113
|
|
114
114
|
should "set timestamp" do
|
115
|
-
hash = @notifier.__send__(:extract_hash, { '
|
115
|
+
hash = @notifier.__send__(:extract_hash, { 'version' => '1.0', 'short_message' => 'message' })
|
116
|
+
assert_instance_of Float, hash['timestamp']
|
116
117
|
now = Time.now.utc.to_i
|
117
|
-
assert ((now - 1)..(now + 1)).include?(hash['
|
118
|
+
assert ((now - 1)..(now + 1)).include?(hash['timestamp'])
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "serialize_hash" do
|
123
|
+
setup do
|
124
|
+
@notifier.instance_variable_set('@hash', { 'level' => GELF::WARN, 'field' => 'value' })
|
125
|
+
@data = @notifier.__send__(:serialize_hash)
|
126
|
+
assert_instance_of Enumerable::Enumerator, @data
|
127
|
+
@deserialized_hash = JSON.parse(Zlib::Inflate.inflate(@data.to_a.pack('C*')))
|
128
|
+
assert_instance_of Hash, @deserialized_hash
|
129
|
+
end
|
130
|
+
|
131
|
+
should "map level" do
|
132
|
+
assert_not_equal GELF::WARN, @deserialized_hash['level']
|
133
|
+
assert_equal GELF::LEVELS_MAPPING[GELF::WARN], @deserialized_hash['level']
|
118
134
|
end
|
119
135
|
end
|
120
136
|
|
121
137
|
context "datagrams_from_hash" do
|
122
138
|
should "not split short data" do
|
123
|
-
@notifier.instance_variable_set('@hash', { '
|
139
|
+
@notifier.instance_variable_set('@hash', { 'version' => '1.0', 'short_message' => 'message' })
|
124
140
|
datagrams = @notifier.__send__(:datagrams_from_hash)
|
125
141
|
assert_equal 1, datagrams.count
|
142
|
+
assert_instance_of String, datagrams[0]
|
126
143
|
assert_equal "\x78\x9c", datagrams[0][0..1] # zlib header
|
127
144
|
end
|
128
145
|
|
129
146
|
should "split long data" do
|
130
147
|
srand(1) # for stable tests
|
131
|
-
hash = { '
|
148
|
+
hash = { 'version' => '1.0', 'short_message' => 'message' }
|
132
149
|
hash.merge!('something' => (0..3000).map { RANDOM_DATA[rand(RANDOM_DATA.count)] }.join) # or it will be compressed too good
|
133
150
|
@notifier.instance_variable_set('@hash', hash)
|
134
151
|
datagrams = @notifier.__send__(:datagrams_from_hash)
|
135
152
|
assert_equal 2, datagrams.count
|
136
153
|
datagrams.each_index do |i|
|
137
154
|
datagram = datagrams[i]
|
155
|
+
assert_instance_of String, datagram
|
138
156
|
assert datagram[0..1] == "\x1e\x0f" # chunked GELF magic number
|
139
157
|
# datagram[2..9] is a message id
|
140
158
|
assert_equal i, datagram[10].ord
|
@@ -146,7 +164,7 @@ class TestNotifier < Test::Unit::TestCase
|
|
146
164
|
context "level threshold" do
|
147
165
|
setup do
|
148
166
|
@notifier.level = GELF::WARN
|
149
|
-
@hash = { '
|
167
|
+
@hash = { 'version' => '1.0', 'short_message' => 'message' }
|
150
168
|
end
|
151
169
|
|
152
170
|
['debug', 'DEBUG', :debug].each do |l|
|
@@ -158,12 +176,12 @@ class TestNotifier < Test::Unit::TestCase
|
|
158
176
|
|
159
177
|
should "not send notifications with level below threshold" do
|
160
178
|
@sender.expects(:send_datagrams).never
|
161
|
-
@notifier.notify!(@hash.merge('
|
179
|
+
@notifier.notify!(@hash.merge('level' => GELF::DEBUG))
|
162
180
|
end
|
163
181
|
|
164
182
|
should "not notifications with level equal or above threshold" do
|
165
183
|
@sender.expects(:send_datagrams).once
|
166
|
-
@notifier.notify!(@hash.merge('
|
184
|
+
@notifier.notify!(@hash.merge('level' => GELF::WARN))
|
167
185
|
end
|
168
186
|
end
|
169
187
|
|
@@ -175,7 +193,7 @@ class TestNotifier < Test::Unit::TestCase
|
|
175
193
|
should "not send datagrams" do
|
176
194
|
@sender.expects(:send_datagrams).never
|
177
195
|
@notifier.expects(:extract_hash).never
|
178
|
-
@notifier.notify!({ '
|
196
|
+
@notifier.notify!({ 'version' => '1.0', 'short_message' => 'message' })
|
179
197
|
end
|
180
198
|
|
181
199
|
context "and enabled again" do
|
@@ -185,7 +203,7 @@ class TestNotifier < Test::Unit::TestCase
|
|
185
203
|
|
186
204
|
should "send datagrams" do
|
187
205
|
@sender.expects(:send_datagrams)
|
188
|
-
@notifier.notify!({ '
|
206
|
+
@notifier.notify!({ 'version' => '1.0', 'short_message' => 'message' })
|
189
207
|
end
|
190
208
|
end
|
191
209
|
end
|
@@ -194,13 +212,13 @@ class TestNotifier < Test::Unit::TestCase
|
|
194
212
|
@sender.expects(:send_datagrams).with do |datagrams|
|
195
213
|
datagrams.is_a?(Array) && datagrams[0].is_a?(String)
|
196
214
|
end
|
197
|
-
@notifier.notify!({ '
|
215
|
+
@notifier.notify!({ 'version' => '1.0', 'short_message' => 'message' })
|
198
216
|
end
|
199
217
|
|
200
218
|
GELF::Levels.constants.each do |const|
|
201
219
|
should "call notify with level #{const} from method name" do
|
202
|
-
@notifier.expects(:notify_with_level).with(GELF.const_get(const), { '
|
203
|
-
@notifier.__send__(const.downcase, { '
|
220
|
+
@notifier.expects(:notify_with_level).with(GELF.const_get(const), { 'version' => '1.0', 'short_message' => 'message' })
|
221
|
+
@notifier.__send__(const.downcase, { 'version' => '1.0', 'short_message' => 'message' })
|
204
222
|
end
|
205
223
|
end
|
206
224
|
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gelf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: -1420906252
|
5
4
|
prerelease: true
|
6
5
|
segments:
|
7
6
|
- 1
|
8
7
|
- 1
|
9
8
|
- 0
|
10
|
-
-
|
11
|
-
version: 1.1.0.
|
9
|
+
- rc1
|
10
|
+
version: 1.1.0.rc1
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- Aleksey Palazhchenko
|
@@ -17,7 +16,7 @@ autorequire:
|
|
17
16
|
bindir: bin
|
18
17
|
cert_chain: []
|
19
18
|
|
20
|
-
date:
|
19
|
+
date: 2011-01-08 00:00:00 +01:00
|
21
20
|
default_executable:
|
22
21
|
dependencies:
|
23
22
|
- !ruby/object:Gem::Dependency
|
@@ -28,7 +27,6 @@ dependencies:
|
|
28
27
|
requirements:
|
29
28
|
- - ">="
|
30
29
|
- !ruby/object:Gem::Version
|
31
|
-
hash: 3
|
32
30
|
segments:
|
33
31
|
- 0
|
34
32
|
version: "0"
|
@@ -42,7 +40,6 @@ dependencies:
|
|
42
40
|
requirements:
|
43
41
|
- - ">="
|
44
42
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 3
|
46
43
|
segments:
|
47
44
|
- 0
|
48
45
|
version: "0"
|
@@ -56,7 +53,6 @@ dependencies:
|
|
56
53
|
requirements:
|
57
54
|
- - ">="
|
58
55
|
- !ruby/object:Gem::Version
|
59
|
-
hash: 3
|
60
56
|
segments:
|
61
57
|
- 0
|
62
58
|
version: "0"
|
@@ -107,7 +103,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
103
|
requirements:
|
108
104
|
- - ">="
|
109
105
|
- !ruby/object:Gem::Version
|
110
|
-
hash: 3
|
111
106
|
segments:
|
112
107
|
- 0
|
113
108
|
version: "0"
|
@@ -116,7 +111,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
111
|
requirements:
|
117
112
|
- - ">"
|
118
113
|
- !ruby/object:Gem::Version
|
119
|
-
hash: 25
|
120
114
|
segments:
|
121
115
|
- 1
|
122
116
|
- 3
|
@@ -131,8 +125,8 @@ specification_version: 3
|
|
131
125
|
summary: Library to send GELF messages to Graylog2 logging server.
|
132
126
|
test_files:
|
133
127
|
- test/helper.rb
|
134
|
-
- test/test_deprecations.rb
|
135
128
|
- test/test_logger.rb
|
136
129
|
- test/test_notifier.rb
|
137
|
-
- test/test_ruby_sender.rb
|
138
130
|
- test/test_severity.rb
|
131
|
+
- test/test_ruby_sender.rb
|
132
|
+
- test/test_deprecations.rb
|