gelf 1.1.0.beta3 → 1.1.0.beta4

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/CHANGELOG CHANGED
@@ -1,6 +1,9 @@
1
- 1.1.0 (not yet released), 2010-11-xx:
1
+ 1.1.0 (not yet released), 2010-12-xx:
2
+ + compatibility with GELF specification 1.0:
3
+ * requires graylog2-server version 0.9.XXXXXXXXXXXX or graylog2-server-twisted;
2
4
  + Notifier#default_options;
3
5
  + severity (level) threshold;
6
+ + automatically set 'file' and 'line' fields;
4
7
  + wrappers for GELF::Notifier#notify with severity:
5
8
  + GELF::Notifier.debug
6
9
  + GELF::Notifier.info
@@ -16,6 +19,10 @@
16
19
  + GELF::Logger#close
17
20
  + GELF::Logger#level = GELF::INFO
18
21
 
22
+ 1.0.2, 2010-11-29:
23
+ 1.0.1, 2010-11-29:
24
+ - added more tests for chunking in attempt to locate not existing bug.
25
+
19
26
  1.0.0, 2010-11-10:
20
27
  + initial stable version;
21
28
  * deprecated Gelf class is still there.
data/Rakefile CHANGED
@@ -6,11 +6,11 @@ begin
6
6
  require 'jeweler'
7
7
  Jeweler::Tasks.new do |gem|
8
8
  gem.name = "gelf"
9
- gem.summary = 'Library to send GELF messages to Graylog2 logging server'
10
- gem.description = 'Suports plain-text, GELF messages and exceptions.'
11
- gem.email = "lennart@socketfeed.com"
9
+ gem.summary = 'Library to send GELF messages to Graylog2 logging server.'
10
+ gem.description = 'Library to send GELF messages to Graylog2 logging server. Supports plain-text, GELF messages and exceptions.'
11
+ gem.email = "aleksey.palazhchenko@gmail.com"
12
12
  gem.homepage = "http://github.com/Graylog2/gelf-rb"
13
- gem.authors = ["Alexey Palazhchenko", "Lennart Koopmann"]
13
+ gem.authors = ["Aleksey Palazhchenko", "Lennart Koopmann"]
14
14
  gem.add_dependency "json"
15
15
  gem.add_development_dependency "shoulda"
16
16
  gem.add_development_dependency "mocha"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0.beta3
1
+ 1.1.0.beta4
@@ -1,15 +1,17 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
- require 'benchmark'
3
+ puts "Loading..."
4
4
 
5
+ require 'benchmark'
5
6
  require 'rubygems'
6
7
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
8
  $LOAD_PATH.unshift(File.dirname(__FILE__))
8
9
  require 'gelf'
9
10
 
11
+ puts "Generating random data..."
10
12
  srand(1)
11
13
  RANDOM_DATA = ('A'..'z').to_a
12
- k1_message = (0..1024).map { RANDOM_DATA[rand(RANDOM_DATA.count)] }.join
14
+ k3_message = (1..3*1024).map { RANDOM_DATA[rand(RANDOM_DATA.count)] }.join
13
15
 
14
16
  TARGET_HOST = 'localhost'
15
17
  TARGET_PORT = 12201
@@ -17,16 +19,21 @@ DEFAULT_OPTIONS = { 'host' => 'localhost' }
17
19
  TIMES = 5000
18
20
 
19
21
  SHORT_HASH = { 'short_message' => 'message' }
20
- LONG_HASH = { 'short_message' => 'short message', 'long_message' => k1_message, 'user_id' => rand(10000)}
22
+ LONG_HASH = { 'short_message' => 'message', 'long_message' => k3_message }
21
23
 
22
24
 
23
25
  notifier_lan = GELF::Notifier.new(TARGET_HOST, TARGET_PORT, 'LAN', DEFAULT_OPTIONS)
24
26
  notifier_wan = GELF::Notifier.new(TARGET_HOST, TARGET_PORT, 'WAN', DEFAULT_OPTIONS)
25
27
 
26
- puts "Sending #{TIMES} notifications..."
27
- tms = Benchmark.bmbm do |b|
28
- b.report('lan, short data') { TIMES.times { notifier_lan.notify!(SHORT_HASH) } }
29
- b.report('wan, short data') { TIMES.times { notifier_wan.notify!(SHORT_HASH) } }
30
- b.report('lan, long data') { TIMES.times { notifier_lan.notify!(LONG_HASH) } }
31
- b.report('wan, long data') { TIMES.times { notifier_wan.notify!(LONG_HASH) } }
28
+ # to create mongo collections, etc.
29
+ notifier_lan.notify!(LONG_HASH)
30
+ sleep(5)
31
+
32
+ puts "Sending #{TIMES} notifications...\n"
33
+ tms = Benchmark.bm(25) do |b|
34
+ b.report('lan, short data, 1 chunk ') { TIMES.times { notifier_lan.notify!(SHORT_HASH) } }
35
+ sleep(5)
36
+ b.report('lan, long data, 1 chunk ') { TIMES.times { notifier_lan.notify!(LONG_HASH) } }
37
+ sleep(5)
38
+ b.report('wan, long data, 2 chunks') { TIMES.times { notifier_wan.notify!(LONG_HASH) } }
32
39
  end
data/gelf.gemspec CHANGED
@@ -5,13 +5,13 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gelf}
8
- s.version = "1.1.0.beta3"
8
+ s.version = "1.1.0.beta4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Alexey Palazhchenko", "Lennart Koopmann"]
12
- s.date = %q{2010-11-26}
13
- s.description = %q{Suports plain-text, GELF messages and exceptions.}
14
- s.email = %q{lennart@socketfeed.com}
11
+ s.authors = ["Aleksey Palazhchenko", "Lennart Koopmann"]
12
+ s.date = %q{2010-12-02}
13
+ s.description = %q{Library to send GELF messages to Graylog2 logging server. Supports plain-text, GELF messages and exceptions.}
14
+ s.email = %q{aleksey.palazhchenko@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.rdoc"
@@ -43,7 +43,7 @@ Gem::Specification.new do |s|
43
43
  s.rdoc_options = ["--charset=UTF-8"]
44
44
  s.require_paths = ["lib"]
45
45
  s.rubygems_version = %q{1.3.7}
46
- s.summary = %q{Library to send GELF messages to Graylog2 logging server}
46
+ s.summary = %q{Library to send GELF messages to Graylog2 logging server.}
47
47
  s.test_files = [
48
48
  "test/helper.rb",
49
49
  "test/test_deprecations.rb",
@@ -8,7 +8,7 @@ class Gelf
8
8
  attr_reader :notifier, :message
9
9
 
10
10
  def initialize(hostname, port)
11
- deprecate('GELF::Notifier.new(hostname, port) and GELF::Message.new')
11
+ deprecate('GELF::Notifier.new(hostname, port)')
12
12
  @notifier = GELF::Notifier.new(hostname, port)
13
13
  @message = {}
14
14
  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 = {'short_message' => message, 'facility' => facility}
23
+ hash = {'gelf_short_message' => message, 'gelf_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('short_message' => message, 'level' => GELF::UNKNOWN)
42
+ notify('gelf_short_message' => message, 'gelf_level' => GELF::UNKNOWN)
43
43
  end
44
44
  end
45
45
 
data/lib/gelf/notifier.rb CHANGED
@@ -21,9 +21,10 @@ module GELF
21
21
 
22
22
  @default_options = {}
23
23
  self.default_options = default_options
24
- self.default_options['host'] ||= Socket.gethostname
25
- self.default_options['level'] ||= GELF::DEBUG
26
- self.default_options['facility'] ||= 'gelf-rb'
24
+ self.default_options['gelf_version'] = SPEC_VERSION
25
+ self.default_options['gelf_host'] ||= Socket.gethostname
26
+ self.default_options['gelf_level'] ||= GELF::DEBUG
27
+ self.default_options['gelf_facility'] ||= 'gelf-rb'
27
28
 
28
29
  @sender = RubySender.new(host, port)
29
30
  end
@@ -95,8 +96,8 @@ module GELF
95
96
  def notify_with_level!(message_level, *args)
96
97
  return unless @enabled
97
98
  extract_hash(*args)
98
- @hash['level'] = message_level unless message_level.nil?
99
- if @hash['level'] >= level
99
+ @hash['gelf_level'] = message_level unless message_level.nil?
100
+ if @hash['gelf_level'] >= level
100
101
  @sender.send_datagrams(datagrams_from_hash)
101
102
  end
102
103
  end
@@ -105,40 +106,53 @@ module GELF
105
106
  primary_data = if object.respond_to?(:to_hash)
106
107
  object.to_hash
107
108
  elsif object.is_a?(Exception)
108
- args['level'] ||= GELF::ERROR
109
+ args['gelf_level'] ||= GELF::ERROR
109
110
  self.class.extract_hash_from_exception(object)
110
111
  else
111
- args['level'] ||= GELF::INFO
112
- { 'short_message' => object.to_s }
112
+ args['gelf_level'] ||= GELF::INFO
113
+ { 'gelf_short_message' => object.to_s }
113
114
  end
114
115
 
115
116
  @hash = default_options.merge(args.merge(primary_data))
116
117
  stringify_hash_keys
117
118
  convert_hoptoad_keys_to_graylog2
119
+ set_file_and_line
118
120
  check_presence_of_mandatory_attributes
119
121
  @hash
120
122
  end
121
123
 
122
124
  def self.extract_hash_from_exception(exception)
123
125
  bt = exception.backtrace || ["Backtrace is not available."]
124
- { 'short_message' => "#{exception.class}: #{exception.message}", 'full_message' => "Backtrace:\n" + bt.join("\n") }
126
+ { 'gelf_short_message' => "#{exception.class}: #{exception.message}", 'gelf_full_message' => "Backtrace:\n" + bt.join("\n") }
125
127
  end
126
128
 
127
129
  # Converts Hoptoad-specific keys in +@hash+ to Graylog2-specific.
128
130
  def convert_hoptoad_keys_to_graylog2
129
- if @hash['short_message'].to_s.empty?
131
+ if @hash['gelf_short_message'].to_s.empty?
130
132
  if @hash.has_key?('error_class') && @hash.has_key?('error_message')
131
- @hash['short_message'] = "#{@hash['error_class']}: #{@hash['error_message']}"
133
+ @hash['gelf_short_message'] = "#{@hash['error_class']}: #{@hash['error_message']}"
132
134
  @hash.delete('error_class')
133
135
  @hash.delete('error_message')
134
136
  end
135
137
  end
136
138
  end
137
139
 
140
+ CALLER_REGEXP = /^(.*):(\d+):.*/
141
+
142
+ def set_file_and_line
143
+ stack = caller
144
+ begin
145
+ frame = stack.shift
146
+ end while frame.include?(__FILE__)
147
+ match = CALLER_REGEXP.match(frame)
148
+ @hash['gelf_file'] = match[1]
149
+ @hash['gelf_line'] = match[2].to_i
150
+ end
151
+
138
152
  def check_presence_of_mandatory_attributes
139
- %w(short_message host).each do |attribute|
153
+ %w(gelf_version gelf_short_message gelf_host).each do |attribute|
140
154
  if @hash[attribute].to_s.empty?
141
- raise ArgumentError.new("Options short_message and host must be set.")
155
+ raise ArgumentError.new("#{attribute} is missing. Options gelf_version, gelf_short_message and gelf_host must be set.")
142
156
  end
143
157
  end
144
158
  end
@@ -146,7 +160,7 @@ module GELF
146
160
  def datagrams_from_hash
147
161
  raise ArgumentError.new("Hash is empty.") if @hash.nil? || @hash.empty?
148
162
 
149
- @hash['level'] = GELF::LEVELS_MAPPING[@hash['level']]
163
+ @hash['gelf_level'] = GELF::LEVELS_MAPPING[@hash['gelf_level']]
150
164
 
151
165
  data = Zlib::Deflate.deflate(@hash.to_json).bytes
152
166
  datagrams = []
@@ -168,8 +182,7 @@ module GELF
168
182
  end
169
183
 
170
184
  def self.chunk_data(data, msg_id, num, count)
171
- # [30, 15].pack('CC') => "\036\017"
172
- return "\036\017" + msg_id + [num, count].pack('nn') + data.map(&:chr).join
185
+ return "\x1e\x0f" + msg_id + [num, count, *data].pack('nnC*')
173
186
  end
174
187
 
175
188
  def stringify_hash_keys
data/lib/gelf.rb CHANGED
@@ -3,6 +3,10 @@ require 'socket'
3
3
  require 'zlib'
4
4
  require 'digest/sha2'
5
5
 
6
+ module GELF
7
+ SPEC_VERSION = '1.0'
8
+ end
9
+
6
10
  require 'gelf/severity'
7
11
  require 'gelf/ruby_sender'
8
12
  require 'gelf/notifier'
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['short_message'] == 'Message'
21
+ hash['gelf_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['short_message'] == 'RuntimeError: Boom!' &&
31
- hash['full_message'] =~ /^Backtrace/
30
+ hash['gelf_short_message'] == 'RuntimeError: Boom!' &&
31
+ hash['gelf_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['short_message'] == 'Message'
40
+ hash['gelf_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['short_message'] == 'RuntimeError: Boom!' &&
50
- hash['full_message'] =~ /^Backtrace/
49
+ hash['gelf_short_message'] == 'RuntimeError: Boom!' &&
50
+ hash['gelf_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['short_message'] == 'Message' &&
60
- hash['facility'] == 'Facility'
59
+ hash['gelf_short_message'] == 'Message' &&
60
+ hash['gelf_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['short_message'] == 'RuntimeError: Boom!' &&
70
- hash['full_message'] =~ /^Backtrace/ &&
71
- hash['facility'] == 'Facility'
69
+ hash['gelf_short_message'] == 'RuntimeError: Boom!' &&
70
+ hash['gelf_full_message'] =~ /^Backtrace/ &&
71
+ hash['gelf_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['short_message'] == 'Message' &&
81
- hash['facility'] == 'Facility'
80
+ hash['gelf_short_message'] == 'Message' &&
81
+ hash['gelf_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['short_message'] == 'RuntimeError: Boom!' &&
91
- hash['full_message'] =~ /^Backtrace/ &&
92
- hash['facility'] == 'Facility'
90
+ hash['gelf_short_message'] == 'RuntimeError: Boom!' &&
91
+ hash['gelf_full_message'] =~ /^Backtrace/ &&
92
+ hash['gelf_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['short_message'] == "Message" &&
130
- hash['level'] == GELF::UNKNOWN
129
+ hash['gelf_short_message'] == "Message" &&
130
+ hash['gelf_level'] == GELF::UNKNOWN
131
131
  end
132
132
  @notifier << "Message"
133
133
  end
@@ -1,6 +1,10 @@
1
1
  require 'helper'
2
2
 
3
- HASH = {'short_message' => 'message', 'host' => 'somehost', 'level' => GELF::WARN, 'facility' => 'test'}
3
+ HASH = { 'gelf_version' => '1.0',
4
+ 'gelf_short_message' => 'message',
5
+ 'gelf_host' => 'somehost',
6
+ 'gelf_level' => GELF::WARN,
7
+ 'gelf_facility' => 'test' }
4
8
 
5
9
  RANDOM_DATA = ('A'..'Z').to_a
6
10
 
@@ -9,10 +13,12 @@ class TestNotifier < Test::Unit::TestCase
9
13
  Socket.expects(:gethostname).returns('default_hostname')
10
14
  n = GELF::Notifier.new
11
15
  assert_equal ['localhost', 12201, 1420], [n.host, n.port, n.max_chunk_size]
12
- assert_equal({'level' => 0, 'host' => 'default_hostname', 'facility' => 'gelf-rb'}, n.default_options)
13
- n.host, n.port, n.max_chunk_size, n.default_options = 'graylog2.org', 7777, :lan, {'host' => 'grayhost'}
16
+ assert_equal( { 'gelf_version' => '1.0', 'gelf_level' => GELF::DEBUG,
17
+ 'gelf_host' => 'default_hostname', 'gelf_facility' => 'gelf-rb' },
18
+ n.default_options )
19
+ n.host, n.port, n.max_chunk_size, n.default_options = 'graylog2.org', 7777, :lan, {'gelf_host' => 'grayhost'}
14
20
  assert_equal ['graylog2.org', 7777, 8154], [n.host, n.port, n.max_chunk_size]
15
- assert_equal({'host' => 'grayhost'}, n.default_options)
21
+ assert_equal({'gelf_host' => 'grayhost'}, n.default_options)
16
22
 
17
23
  n.max_chunk_size = 1337.1
18
24
  assert_equal 1337, n.max_chunk_size
@@ -33,71 +39,84 @@ class TestNotifier < Test::Unit::TestCase
33
39
  end
34
40
 
35
41
  should "work with hash" do
36
- assert_equal HASH, @notifier.__send__(:extract_hash, HASH)
42
+ hash = @notifier.__send__(:extract_hash, HASH)
43
+ hash.delete('gelf_file')
44
+ hash.delete('gelf_line')
45
+ assert_equal HASH, hash
37
46
  end
38
47
 
39
48
  should "work with any object which responds to #to_hash" do
40
49
  o = Object.new
41
50
  o.expects(:to_hash).returns(HASH)
42
- assert_equal HASH, @notifier.__send__(:extract_hash, o)
51
+ hash = @notifier.__send__(:extract_hash, o)
52
+ hash.delete('gelf_file')
53
+ hash.delete('gelf_line')
54
+ assert_equal HASH, hash
43
55
  end
44
56
 
45
57
  should "work with exception with backtrace" do
46
58
  e = RuntimeError.new('message')
47
59
  e.set_backtrace(caller)
48
60
  hash = @notifier.__send__(:extract_hash, e)
49
- assert_equal 'RuntimeError: message', hash['short_message']
50
- assert_match /Backtrace/, hash['full_message']
51
- assert_equal GELF::ERROR, hash['level']
61
+ assert_equal 'RuntimeError: message', hash['gelf_short_message']
62
+ assert_match /Backtrace/, hash['gelf_full_message']
63
+ assert_equal GELF::ERROR, hash['gelf_level']
52
64
  end
53
65
 
54
66
  should "work with exception without backtrace" do
55
67
  e = RuntimeError.new('message')
56
68
  hash = @notifier.__send__(:extract_hash, e)
57
- assert_match /Backtrace is not available/, hash['full_message']
69
+ assert_match /Backtrace is not available/, hash['gelf_full_message']
58
70
  end
59
71
 
60
72
  should "work with exception and hash" do
61
- e, h = RuntimeError.new('message'), {'param' => 1, 'level' => GELF::FATAL, 'short_message' => 'will be hidden by exception'}
73
+ e, h = RuntimeError.new('message'), {'param' => 1, 'gelf_level' => GELF::FATAL, 'gelf_short_message' => 'will be hidden by exception'}
62
74
  hash = @notifier.__send__(:extract_hash, e, h)
63
- assert_equal 'RuntimeError: message', hash['short_message']
64
- assert_equal GELF::FATAL, hash['level']
75
+ assert_equal 'RuntimeError: message', hash['gelf_short_message']
76
+ assert_equal GELF::FATAL, hash['gelf_level']
65
77
  assert_equal 1, hash['param']
66
78
  end
67
79
 
68
80
  should "work with plain text" do
69
81
  hash = @notifier.__send__(:extract_hash, 'message')
70
- assert_equal 'message', hash['short_message']
71
- assert_equal GELF::INFO, hash['level']
82
+ assert_equal 'message', hash['gelf_short_message']
83
+ assert_equal GELF::INFO, hash['gelf_level']
72
84
  end
73
85
 
74
86
  should "work with plain text and hash" do
75
- hash = @notifier.__send__(:extract_hash, 'message', 'level' => GELF::WARN)
76
- assert_equal 'message', hash['short_message']
77
- assert_equal GELF::WARN, hash['level']
87
+ hash = @notifier.__send__(:extract_hash, 'message', 'gelf_level' => GELF::WARN)
88
+ assert_equal 'message', hash['gelf_short_message']
89
+ assert_equal GELF::WARN, hash['gelf_level']
78
90
  end
79
91
 
80
92
  should "covert hash keys to strings" do
81
- hash = @notifier.__send__(:extract_hash, :short_message => :message)
82
- assert hash.has_key?('short_message')
83
- assert !hash.has_key?(:short_message)
93
+ hash = @notifier.__send__(:extract_hash, :gelf_short_message => :message)
94
+ assert hash.has_key?('gelf_short_message')
95
+ assert !hash.has_key?(:gelf_short_message)
84
96
  end
85
97
 
86
98
  should "not overwrite keys on convert" do
87
- assert_raise(ArgumentError) { @notifier.__send__(:extract_hash, :short_message => :message1, 'short_message' => 'message2') }
99
+ assert_raise(ArgumentError) { @notifier.__send__(:extract_hash, :gelf_short_message => :message1, 'gelf_short_message' => 'message2') }
88
100
  end
89
101
 
90
102
  should "use default_options" do
91
- @notifier.default_options = {:file => 'somefile.rb', 'short_message' => 'will be hidden by explicit argument'}
103
+ @notifier.default_options = {:foo => 'bar', 'gelf_short_message' => 'will be hidden by explicit argument'}
92
104
  hash = @notifier.__send__(:extract_hash, HASH)
93
- assert_equal 'somefile.rb', hash['file']
94
- assert_not_equal 'will be hidden by explicit argument', hash['short_message']
105
+ assert_equal 'bar', hash['foo']
106
+ assert_not_equal 'will be hidden by explicit argument', hash['gelf_short_message']
95
107
  end
96
108
 
97
109
  should "be compatible with HoptoadNotifier" do
98
110
  # https://github.com/thoughtbot/hoptoad_notifier/blob/master/README.rdoc, section Going beyond exceptions
99
111
  hash = @notifier.__send__(:extract_hash, :error_class => 'Class', :error_message => 'Message')
100
- assert_equal 'Class: Message', hash['short_message']
112
+ assert_equal 'Class: Message', hash['gelf_short_message']
113
+ end
114
+
115
+ should "set file and line" do
116
+ line = __LINE__
117
+ hash = @notifier.__send__(:extract_hash, HASH)
118
+ assert_match /test_notifier.rb/, hash['gelf_file']
119
+ assert_equal line + 1, hash['gelf_line']
101
120
  end
102
121
  end
103
122
 
@@ -106,7 +125,7 @@ class TestNotifier < Test::Unit::TestCase
106
125
  @notifier.instance_variable_set('@hash', HASH)
107
126
  datagrams = @notifier.__send__(:datagrams_from_hash)
108
127
  assert_equal 1, datagrams.count
109
- assert_equal "\170\234", datagrams[0][0..1]
128
+ assert_equal "\x78\x9c", datagrams[0][0..1] # zlib header
110
129
  end
111
130
 
112
131
  should "split long data" do
@@ -115,8 +134,15 @@ class TestNotifier < Test::Unit::TestCase
115
134
  @notifier.instance_variable_set('@hash', hash)
116
135
  datagrams = @notifier.__send__(:datagrams_from_hash)
117
136
  assert_equal 2, datagrams.count
118
- assert_equal "\036\017", datagrams[0][0..1]
119
- assert_equal "\036\017", datagrams[1][0..1]
137
+ datagrams.each_index do |i|
138
+ datagram = datagrams[i]
139
+ assert datagram[0..1] == "\x1e\x0f" # chunked GELF magic number
140
+ # datagram[2..33] is a message id
141
+ assert_equal 0, datagram[34].ord
142
+ assert_equal i, datagram[35].ord
143
+ assert_equal 0, datagram[36].ord
144
+ assert_equal datagrams.count, datagram[37].ord
145
+ end
120
146
  end
121
147
  end
122
148
 
@@ -134,12 +160,12 @@ class TestNotifier < Test::Unit::TestCase
134
160
 
135
161
  should "not send notifications with level below threshold" do
136
162
  @sender.expects(:send_datagrams).never
137
- @notifier.notify!(HASH.merge('level' => GELF::DEBUG))
163
+ @notifier.notify!(HASH.merge('gelf_level' => GELF::DEBUG))
138
164
  end
139
165
 
140
166
  should "not notifications with level equal or above threshold" do
141
167
  @sender.expects(:send_datagrams).once
142
- @notifier.notify!(HASH.merge('level' => GELF::WARN))
168
+ @notifier.notify!(HASH.merge('gelf_level' => GELF::WARN))
143
169
  end
144
170
  end
145
171
 
metadata CHANGED
@@ -1,23 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gelf
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1848230061
4
+ hash: -1848230064
5
5
  prerelease: true
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
9
  - 0
10
- - beta3
11
- version: 1.1.0.beta3
10
+ - beta4
11
+ version: 1.1.0.beta4
12
12
  platform: ruby
13
13
  authors:
14
- - Alexey Palazhchenko
14
+ - Aleksey Palazhchenko
15
15
  - Lennart Koopmann
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-11-26 00:00:00 +03:00
20
+ date: 2010-12-02 00:00:00 +03:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -62,8 +62,8 @@ dependencies:
62
62
  version: "0"
63
63
  type: :development
64
64
  version_requirements: *id003
65
- description: Suports plain-text, GELF messages and exceptions.
66
- email: lennart@socketfeed.com
65
+ description: Library to send GELF messages to Graylog2 logging server. Supports plain-text, GELF messages and exceptions.
66
+ email: aleksey.palazhchenko@gmail.com
67
67
  executables: []
68
68
 
69
69
  extensions: []
@@ -128,7 +128,7 @@ rubyforge_project:
128
128
  rubygems_version: 1.3.7
129
129
  signing_key:
130
130
  specification_version: 3
131
- summary: Library to send GELF messages to Graylog2 logging server
131
+ summary: Library to send GELF messages to Graylog2 logging server.
132
132
  test_files:
133
133
  - test/helper.rb
134
134
  - test/test_deprecations.rb