gelf 1.1.0.beta4 → 1.1.0.beta6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/benchmarks/notifier.rb +3 -3
- data/gelf.gemspec +2 -2
- data/lib/gelf.rb +1 -1
- data/lib/gelf/em_sender.rb +19 -10
- data/lib/gelf/logger.rb +2 -2
- data/lib/gelf/notifier.rb +21 -21
- data/lib/gelf/ruby_sender.rb +16 -2
- data/test/test_logger.rb +18 -18
- data/test/test_notifier.rb +39 -41
- data/test/test_ruby_sender.rb +2 -2
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.0.
|
1
|
+
1.1.0.beta6
|
data/benchmarks/notifier.rb
CHANGED
@@ -15,11 +15,11 @@ k3_message = (1..3*1024).map { RANDOM_DATA[rand(RANDOM_DATA.count)] }.join
|
|
15
15
|
|
16
16
|
TARGET_HOST = 'localhost'
|
17
17
|
TARGET_PORT = 12201
|
18
|
-
DEFAULT_OPTIONS = { '
|
18
|
+
DEFAULT_OPTIONS = { '_host' => 'localhost' }
|
19
19
|
TIMES = 5000
|
20
20
|
|
21
|
-
SHORT_HASH = { '
|
22
|
-
LONG_HASH = { '
|
21
|
+
SHORT_HASH = { '_short_message' => 'message' }
|
22
|
+
LONG_HASH = { '_short_message' => 'message', '_long_message' => k3_message }
|
23
23
|
|
24
24
|
|
25
25
|
notifier_lan = GELF::Notifier.new(TARGET_HOST, TARGET_PORT, 'LAN', DEFAULT_OPTIONS)
|
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.beta6"
|
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{2010-12-
|
12
|
+
s.date = %q{2010-12-03}
|
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 = [
|
data/lib/gelf.rb
CHANGED
data/lib/gelf/em_sender.rb
CHANGED
@@ -1,10 +1,19 @@
|
|
1
|
-
module GELF
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
# module GELF
|
2
|
+
# # TCP Sender for EventMachine.
|
3
|
+
# class EMTcpSender
|
4
|
+
# def initialize(host, port)
|
5
|
+
# end
|
6
|
+
#
|
7
|
+
# def send_datagrams(datagrams)
|
8
|
+
# end
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# # UDP Sender for EventMachine.
|
12
|
+
# class EMUdpSender
|
13
|
+
# def initialize(host, port)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# def send_datagrams(datagrams)
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
# end
|
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
|
@@ -39,7 +39,7 @@ module GELF
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def <<(message)
|
42
|
-
notify('
|
42
|
+
notify('_short_message' => message, '_level' => GELF::UNKNOWN)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
data/lib/gelf/notifier.rb
CHANGED
@@ -21,12 +21,12 @@ module GELF
|
|
21
21
|
|
22
22
|
@default_options = {}
|
23
23
|
self.default_options = default_options
|
24
|
-
self.default_options['
|
25
|
-
self.default_options['
|
26
|
-
self.default_options['
|
27
|
-
self.default_options['
|
24
|
+
self.default_options['_version'] = SPEC_VERSION
|
25
|
+
self.default_options['_host'] ||= Socket.gethostname
|
26
|
+
self.default_options['_level'] ||= GELF::DEBUG
|
27
|
+
self.default_options['_facility'] ||= 'gelf-rb'
|
28
28
|
|
29
|
-
@sender =
|
29
|
+
@sender = RubyUdpSender.new(host, port)
|
30
30
|
end
|
31
31
|
|
32
32
|
# +size+ may be a number of bytes, 'WAN' (1420 bytes) or 'LAN' (8154).
|
@@ -96,8 +96,8 @@ module GELF
|
|
96
96
|
def notify_with_level!(message_level, *args)
|
97
97
|
return unless @enabled
|
98
98
|
extract_hash(*args)
|
99
|
-
@hash['
|
100
|
-
if @hash['
|
99
|
+
@hash['_level'] = message_level unless message_level.nil?
|
100
|
+
if @hash['_level'] >= level
|
101
101
|
@sender.send_datagrams(datagrams_from_hash)
|
102
102
|
end
|
103
103
|
end
|
@@ -106,11 +106,11 @@ module GELF
|
|
106
106
|
primary_data = if object.respond_to?(:to_hash)
|
107
107
|
object.to_hash
|
108
108
|
elsif object.is_a?(Exception)
|
109
|
-
args['
|
109
|
+
args['_level'] ||= GELF::ERROR
|
110
110
|
self.class.extract_hash_from_exception(object)
|
111
111
|
else
|
112
|
-
args['
|
113
|
-
{ '
|
112
|
+
args['_level'] ||= GELF::INFO
|
113
|
+
{ '_short_message' => object.to_s }
|
114
114
|
end
|
115
115
|
|
116
116
|
@hash = default_options.merge(args.merge(primary_data))
|
@@ -123,21 +123,21 @@ module GELF
|
|
123
123
|
|
124
124
|
def self.extract_hash_from_exception(exception)
|
125
125
|
bt = exception.backtrace || ["Backtrace is not available."]
|
126
|
-
{ '
|
126
|
+
{ '_short_message' => "#{exception.class}: #{exception.message}", '_full_message' => "Backtrace:\n" + bt.join("\n") }
|
127
127
|
end
|
128
128
|
|
129
129
|
# Converts Hoptoad-specific keys in +@hash+ to Graylog2-specific.
|
130
130
|
def convert_hoptoad_keys_to_graylog2
|
131
|
-
if @hash['
|
131
|
+
if @hash['_short_message'].to_s.empty?
|
132
132
|
if @hash.has_key?('error_class') && @hash.has_key?('error_message')
|
133
|
-
@hash['
|
133
|
+
@hash['_short_message'] = "#{@hash['error_class']}: #{@hash['error_message']}"
|
134
134
|
@hash.delete('error_class')
|
135
135
|
@hash.delete('error_message')
|
136
136
|
end
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
-
CALLER_REGEXP = /^(.*):(\d+)
|
140
|
+
CALLER_REGEXP = /^(.*):(\d+).*/
|
141
141
|
|
142
142
|
def set_file_and_line
|
143
143
|
stack = caller
|
@@ -145,14 +145,14 @@ module GELF
|
|
145
145
|
frame = stack.shift
|
146
146
|
end while frame.include?(__FILE__)
|
147
147
|
match = CALLER_REGEXP.match(frame)
|
148
|
-
@hash['
|
149
|
-
@hash['
|
148
|
+
@hash['_file'] = match[1]
|
149
|
+
@hash['_line'] = match[2].to_i
|
150
150
|
end
|
151
151
|
|
152
152
|
def check_presence_of_mandatory_attributes
|
153
|
-
%w(
|
153
|
+
%w(_version _short_message _host).each do |attribute|
|
154
154
|
if @hash[attribute].to_s.empty?
|
155
|
-
raise ArgumentError.new("#{attribute} is missing. Options
|
155
|
+
raise ArgumentError.new("#{attribute} is missing. Options _version, _short_message and _host must be set.")
|
156
156
|
end
|
157
157
|
end
|
158
158
|
end
|
@@ -160,7 +160,7 @@ module GELF
|
|
160
160
|
def datagrams_from_hash
|
161
161
|
raise ArgumentError.new("Hash is empty.") if @hash.nil? || @hash.empty?
|
162
162
|
|
163
|
-
@hash['
|
163
|
+
@hash['_level'] = GELF::LEVELS_MAPPING[@hash['_level']]
|
164
164
|
|
165
165
|
data = Zlib::Deflate.deflate(@hash.to_json).bytes
|
166
166
|
datagrams = []
|
@@ -168,7 +168,7 @@ module GELF
|
|
168
168
|
# Maximum total size is 8192 byte for UDP datagram. Split to chunks if bigger. (GELFv2 supports chunking)
|
169
169
|
if data.count > @max_chunk_size
|
170
170
|
id = self.class.last_chunk_id += 1
|
171
|
-
msg_id = Digest::
|
171
|
+
msg_id = Digest::MD5.digest("#{Time.now.to_f}-#{id}")[0, 8]
|
172
172
|
num, count = 0, (data.count.to_f / @max_chunk_size).ceil
|
173
173
|
data.each_slice(@max_chunk_size) do |slice|
|
174
174
|
datagrams << self.class.chunk_data(slice, msg_id, num, count)
|
@@ -182,7 +182,7 @@ module GELF
|
|
182
182
|
end
|
183
183
|
|
184
184
|
def self.chunk_data(data, msg_id, num, count)
|
185
|
-
return "\x1e\x0f" + msg_id + [num, count, *data].pack('
|
185
|
+
return "\x1e\x0f" + msg_id + [num, count, *data].pack('C*')
|
186
186
|
end
|
187
187
|
|
188
188
|
def stringify_hash_keys
|
data/lib/gelf/ruby_sender.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module GELF
|
2
|
-
# Plain Ruby sender.
|
3
|
-
class
|
2
|
+
# Plain Ruby UDP sender.
|
3
|
+
class RubyUdpSender
|
4
4
|
def initialize(host, port)
|
5
5
|
@host, @port = host, port
|
6
6
|
@socket = UDPSocket.open
|
@@ -12,4 +12,18 @@ module GELF
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
|
+
|
16
|
+
# Plain Ruby TCP sender.
|
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
|
15
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
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
HASH = { '
|
4
|
-
'
|
5
|
-
'
|
6
|
-
'
|
7
|
-
'
|
3
|
+
HASH = { '_version' => '1.0',
|
4
|
+
'_short_message' => 'message',
|
5
|
+
'_host' => 'somehost',
|
6
|
+
'_level' => GELF::WARN,
|
7
|
+
'_facility' => 'test' }
|
8
8
|
|
9
9
|
RANDOM_DATA = ('A'..'Z').to_a
|
10
10
|
|
@@ -13,12 +13,12 @@ class TestNotifier < Test::Unit::TestCase
|
|
13
13
|
Socket.expects(:gethostname).returns('default_hostname')
|
14
14
|
n = GELF::Notifier.new
|
15
15
|
assert_equal ['localhost', 12201, 1420], [n.host, n.port, n.max_chunk_size]
|
16
|
-
assert_equal( { '
|
17
|
-
'
|
16
|
+
assert_equal( { '_version' => '1.0', '_level' => GELF::DEBUG,
|
17
|
+
'_host' => 'default_hostname', '_facility' => 'gelf-rb' },
|
18
18
|
n.default_options )
|
19
|
-
n.host, n.port, n.max_chunk_size, n.default_options = 'graylog2.org', 7777, :lan, {'
|
19
|
+
n.host, n.port, n.max_chunk_size, n.default_options = 'graylog2.org', 7777, :lan, {'_host' => 'grayhost'}
|
20
20
|
assert_equal ['graylog2.org', 7777, 8154], [n.host, n.port, n.max_chunk_size]
|
21
|
-
assert_equal({'
|
21
|
+
assert_equal({'_host' => 'grayhost'}, n.default_options)
|
22
22
|
|
23
23
|
n.max_chunk_size = 1337.1
|
24
24
|
assert_equal 1337, n.max_chunk_size
|
@@ -40,8 +40,8 @@ class TestNotifier < Test::Unit::TestCase
|
|
40
40
|
|
41
41
|
should "work with hash" do
|
42
42
|
hash = @notifier.__send__(:extract_hash, HASH)
|
43
|
-
hash.delete('
|
44
|
-
hash.delete('
|
43
|
+
hash.delete('_file')
|
44
|
+
hash.delete('_line')
|
45
45
|
assert_equal HASH, hash
|
46
46
|
end
|
47
47
|
|
@@ -49,8 +49,8 @@ class TestNotifier < Test::Unit::TestCase
|
|
49
49
|
o = Object.new
|
50
50
|
o.expects(:to_hash).returns(HASH)
|
51
51
|
hash = @notifier.__send__(:extract_hash, o)
|
52
|
-
hash.delete('
|
53
|
-
hash.delete('
|
52
|
+
hash.delete('_file')
|
53
|
+
hash.delete('_line')
|
54
54
|
assert_equal HASH, hash
|
55
55
|
end
|
56
56
|
|
@@ -58,65 +58,65 @@ class TestNotifier < Test::Unit::TestCase
|
|
58
58
|
e = RuntimeError.new('message')
|
59
59
|
e.set_backtrace(caller)
|
60
60
|
hash = @notifier.__send__(:extract_hash, e)
|
61
|
-
assert_equal 'RuntimeError: message', hash['
|
62
|
-
assert_match /Backtrace/, hash['
|
63
|
-
assert_equal GELF::ERROR, hash['
|
61
|
+
assert_equal 'RuntimeError: message', hash['_short_message']
|
62
|
+
assert_match /Backtrace/, hash['_full_message']
|
63
|
+
assert_equal GELF::ERROR, hash['_level']
|
64
64
|
end
|
65
65
|
|
66
66
|
should "work with exception without backtrace" do
|
67
67
|
e = RuntimeError.new('message')
|
68
68
|
hash = @notifier.__send__(:extract_hash, e)
|
69
|
-
assert_match /Backtrace is not available/, hash['
|
69
|
+
assert_match /Backtrace is not available/, hash['_full_message']
|
70
70
|
end
|
71
71
|
|
72
72
|
should "work with exception and hash" do
|
73
|
-
e, h = RuntimeError.new('message'), {'param' => 1, '
|
73
|
+
e, h = RuntimeError.new('message'), {'param' => 1, '_level' => GELF::FATAL, '_short_message' => 'will be hidden by exception'}
|
74
74
|
hash = @notifier.__send__(:extract_hash, e, h)
|
75
|
-
assert_equal 'RuntimeError: message', hash['
|
76
|
-
assert_equal GELF::FATAL, hash['
|
75
|
+
assert_equal 'RuntimeError: message', hash['_short_message']
|
76
|
+
assert_equal GELF::FATAL, hash['_level']
|
77
77
|
assert_equal 1, hash['param']
|
78
78
|
end
|
79
79
|
|
80
80
|
should "work with plain text" do
|
81
81
|
hash = @notifier.__send__(:extract_hash, 'message')
|
82
|
-
assert_equal 'message', hash['
|
83
|
-
assert_equal GELF::INFO, hash['
|
82
|
+
assert_equal 'message', hash['_short_message']
|
83
|
+
assert_equal GELF::INFO, hash['_level']
|
84
84
|
end
|
85
85
|
|
86
86
|
should "work with plain text and hash" do
|
87
|
-
hash = @notifier.__send__(:extract_hash, 'message', '
|
88
|
-
assert_equal 'message', hash['
|
89
|
-
assert_equal GELF::WARN, hash['
|
87
|
+
hash = @notifier.__send__(:extract_hash, 'message', '_level' => GELF::WARN)
|
88
|
+
assert_equal 'message', hash['_short_message']
|
89
|
+
assert_equal GELF::WARN, hash['_level']
|
90
90
|
end
|
91
91
|
|
92
92
|
should "covert hash keys to strings" do
|
93
|
-
hash = @notifier.__send__(:extract_hash, :
|
94
|
-
assert hash.has_key?('
|
95
|
-
assert !hash.has_key?(:
|
93
|
+
hash = @notifier.__send__(:extract_hash, :_short_message => :message)
|
94
|
+
assert hash.has_key?('_short_message')
|
95
|
+
assert !hash.has_key?(:_short_message)
|
96
96
|
end
|
97
97
|
|
98
98
|
should "not overwrite keys on convert" do
|
99
|
-
assert_raise(ArgumentError) { @notifier.__send__(:extract_hash, :
|
99
|
+
assert_raise(ArgumentError) { @notifier.__send__(:extract_hash, :_short_message => :message1, '_short_message' => 'message2') }
|
100
100
|
end
|
101
101
|
|
102
102
|
should "use default_options" do
|
103
|
-
@notifier.default_options = {:foo => 'bar', '
|
103
|
+
@notifier.default_options = {:foo => 'bar', '_short_message' => 'will be hidden by explicit argument'}
|
104
104
|
hash = @notifier.__send__(:extract_hash, HASH)
|
105
105
|
assert_equal 'bar', hash['foo']
|
106
|
-
assert_not_equal 'will be hidden by explicit argument', hash['
|
106
|
+
assert_not_equal 'will be hidden by explicit argument', hash['_short_message']
|
107
107
|
end
|
108
108
|
|
109
109
|
should "be compatible with HoptoadNotifier" do
|
110
110
|
# https://github.com/thoughtbot/hoptoad_notifier/blob/master/README.rdoc, section Going beyond exceptions
|
111
111
|
hash = @notifier.__send__(:extract_hash, :error_class => 'Class', :error_message => 'Message')
|
112
|
-
assert_equal 'Class: Message', hash['
|
112
|
+
assert_equal 'Class: Message', hash['_short_message']
|
113
113
|
end
|
114
114
|
|
115
115
|
should "set file and line" do
|
116
116
|
line = __LINE__
|
117
117
|
hash = @notifier.__send__(:extract_hash, HASH)
|
118
|
-
assert_match /test_notifier.rb/, hash['
|
119
|
-
assert_equal line + 1, hash['
|
118
|
+
assert_match /test_notifier.rb/, hash['_file']
|
119
|
+
assert_equal line + 1, hash['_line']
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
@@ -137,11 +137,9 @@ class TestNotifier < Test::Unit::TestCase
|
|
137
137
|
datagrams.each_index do |i|
|
138
138
|
datagram = datagrams[i]
|
139
139
|
assert datagram[0..1] == "\x1e\x0f" # chunked GELF magic number
|
140
|
-
# datagram[2..
|
141
|
-
assert_equal
|
142
|
-
assert_equal
|
143
|
-
assert_equal 0, datagram[36].ord
|
144
|
-
assert_equal datagrams.count, datagram[37].ord
|
140
|
+
# datagram[2..9] is a message id
|
141
|
+
assert_equal i, datagram[10].ord
|
142
|
+
assert_equal datagrams.count, datagram[11].ord
|
145
143
|
end
|
146
144
|
end
|
147
145
|
end
|
@@ -160,12 +158,12 @@ class TestNotifier < Test::Unit::TestCase
|
|
160
158
|
|
161
159
|
should "not send notifications with level below threshold" do
|
162
160
|
@sender.expects(:send_datagrams).never
|
163
|
-
@notifier.notify!(HASH.merge('
|
161
|
+
@notifier.notify!(HASH.merge('_level' => GELF::DEBUG))
|
164
162
|
end
|
165
163
|
|
166
164
|
should "not notifications with level equal or above threshold" do
|
167
165
|
@sender.expects(:send_datagrams).once
|
168
|
-
@notifier.notify!(HASH.merge('
|
166
|
+
@notifier.notify!(HASH.merge('_level' => GELF::WARN))
|
169
167
|
end
|
170
168
|
end
|
171
169
|
|
data/test/test_ruby_sender.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestRubyUdpSender < Test::Unit::TestCase
|
4
4
|
context "with ruby sender" do
|
5
5
|
setup do
|
6
6
|
@host, @port = 'localhost', 12201
|
7
|
-
@sender = GELF::
|
7
|
+
@sender = GELF::RubyUdpSender.new('localhost', 12201)
|
8
8
|
@datagrams = %w(d1 d2 d3)
|
9
9
|
end
|
10
10
|
|
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: -1848230050
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
9
|
- 0
|
10
|
-
-
|
11
|
-
version: 1.1.0.
|
10
|
+
- beta6
|
11
|
+
version: 1.1.0.beta6
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Aleksey Palazhchenko
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-12-
|
20
|
+
date: 2010-12-03 00:00:00 +03:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|