gelf 1.1.0.beta6 → 1.1.0.gamma1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,9 +1,10 @@
1
1
  1.1.0 (not yet released), 2010-12-xx:
2
2
  + compatibility with GELF specification 1.0:
3
- * requires graylog2-server version 0.9.XXXXXXXXXXXX or graylog2-server-twisted;
3
+ * requires graylog2-server version after 0.9.XXXXXXXXXXXX or graylog2-server-twisted;
4
+ * requires graylog2-web-interface version XXXXXXXXXXXX;
4
5
  + Notifier#default_options;
5
6
  + severity (level) threshold;
6
- + automatically set 'file' and 'line' fields;
7
+ + automatically set '_file', '_line' and '_timestamp', fields;
7
8
  + wrappers for GELF::Notifier#notify with severity:
8
9
  + GELF::Notifier.debug
9
10
  + GELF::Notifier.info
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0.beta6
1
+ 1.1.0.gamma1
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.beta6"
8
+ s.version = "1.1.0.gamma1"
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-03}
12
+ s.date = %q{2010-12-09}
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/logger.rb CHANGED
@@ -25,6 +25,7 @@ module GELF
25
25
  notify_with_level(level, hash)
26
26
  end
27
27
 
28
+ # Redefines methods in +Notifier+.
28
29
  GELF::Levels.constants.each do |const|
29
30
  class_eval <<-EOT, __FILE__, __LINE__ + 1
30
31
  def #{const.downcase}(*args) # def debug(*args)
data/lib/gelf/notifier.rb CHANGED
@@ -117,6 +117,7 @@ module GELF
117
117
  stringify_hash_keys
118
118
  convert_hoptoad_keys_to_graylog2
119
119
  set_file_and_line
120
+ set_timestamp
120
121
  check_presence_of_mandatory_attributes
121
122
  @hash
122
123
  end
@@ -138,17 +139,22 @@ module GELF
138
139
  end
139
140
 
140
141
  CALLER_REGEXP = /^(.*):(\d+).*/
142
+ LIB_GELF_PATTERN = File.join('lib', 'gelf')
141
143
 
142
144
  def set_file_and_line
143
145
  stack = caller
144
146
  begin
145
147
  frame = stack.shift
146
- end while frame.include?(__FILE__)
148
+ end while frame.include?(LIB_GELF_PATTERN)
147
149
  match = CALLER_REGEXP.match(frame)
148
150
  @hash['_file'] = match[1]
149
151
  @hash['_line'] = match[2].to_i
150
152
  end
151
153
 
154
+ def set_timestamp
155
+ @hash['_timestamp'] = Time.now.utc.to_f
156
+ end
157
+
152
158
  def check_presence_of_mandatory_attributes
153
159
  %w(_version _short_message _host).each do |attribute|
154
160
  if @hash[attribute].to_s.empty?
@@ -1,11 +1,5 @@
1
1
  require 'helper'
2
2
 
3
- HASH = { '_version' => '1.0',
4
- '_short_message' => 'message',
5
- '_host' => 'somehost',
6
- '_level' => GELF::WARN,
7
- '_facility' => 'test' }
8
-
9
3
  RANDOM_DATA = ('A'..'Z').to_a
10
4
 
11
5
  class TestNotifier < Test::Unit::TestCase
@@ -39,19 +33,17 @@ class TestNotifier < Test::Unit::TestCase
39
33
  end
40
34
 
41
35
  should "work with hash" do
42
- hash = @notifier.__send__(:extract_hash, HASH)
43
- hash.delete('_file')
44
- hash.delete('_line')
45
- assert_equal HASH, 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']
46
39
  end
47
40
 
48
41
  should "work with any object which responds to #to_hash" do
49
42
  o = Object.new
50
- o.expects(:to_hash).returns(HASH)
43
+ o.expects(:to_hash).returns({ '_version' => '1.0', '_short_message' => 'message' })
51
44
  hash = @notifier.__send__(:extract_hash, o)
52
- hash.delete('_file')
53
- hash.delete('_line')
54
- assert_equal HASH, hash
45
+ assert_equal '1.0', hash['_version']
46
+ assert_equal 'message', hash['_short_message']
55
47
  end
56
48
 
57
49
  should "work with exception with backtrace" do
@@ -100,10 +92,10 @@ class TestNotifier < Test::Unit::TestCase
100
92
  end
101
93
 
102
94
  should "use default_options" do
103
- @notifier.default_options = {:foo => 'bar', '_short_message' => 'will be hidden by explicit argument'}
104
- hash = @notifier.__send__(:extract_hash, 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' })
105
97
  assert_equal 'bar', hash['foo']
106
- assert_not_equal 'will be hidden by explicit argument', hash['_short_message']
98
+ assert_equal 'message', hash['_short_message']
107
99
  end
108
100
 
109
101
  should "be compatible with HoptoadNotifier" do
@@ -114,15 +106,21 @@ class TestNotifier < Test::Unit::TestCase
114
106
 
115
107
  should "set file and line" do
116
108
  line = __LINE__
117
- hash = @notifier.__send__(:extract_hash, HASH)
109
+ hash = @notifier.__send__(:extract_hash, { '_version' => '1.0', '_short_message' => 'message' })
118
110
  assert_match /test_notifier.rb/, hash['_file']
119
111
  assert_equal line + 1, hash['_line']
120
112
  end
113
+
114
+ should "set timestamp" do
115
+ hash = @notifier.__send__(:extract_hash, { '_version' => '1.0', '_short_message' => 'message' })
116
+ now = Time.now.utc.to_i
117
+ assert ((now - 1)..(now + 1)).include?(hash['_timestamp'])
118
+ end
121
119
  end
122
120
 
123
121
  context "datagrams_from_hash" do
124
122
  should "not split short data" do
125
- @notifier.instance_variable_set('@hash', HASH)
123
+ @notifier.instance_variable_set('@hash', { '_version' => '1.0', '_short_message' => 'message' })
126
124
  datagrams = @notifier.__send__(:datagrams_from_hash)
127
125
  assert_equal 1, datagrams.count
128
126
  assert_equal "\x78\x9c", datagrams[0][0..1] # zlib header
@@ -130,7 +128,8 @@ class TestNotifier < Test::Unit::TestCase
130
128
 
131
129
  should "split long data" do
132
130
  srand(1) # for stable tests
133
- hash = HASH.merge('something' => (0..3000).map { RANDOM_DATA[rand(RANDOM_DATA.count)] }.join) # or it will be compressed too good
131
+ hash = { '_version' => '1.0', '_short_message' => 'message' }
132
+ hash.merge!('something' => (0..3000).map { RANDOM_DATA[rand(RANDOM_DATA.count)] }.join) # or it will be compressed too good
134
133
  @notifier.instance_variable_set('@hash', hash)
135
134
  datagrams = @notifier.__send__(:datagrams_from_hash)
136
135
  assert_equal 2, datagrams.count
@@ -147,6 +146,7 @@ class TestNotifier < Test::Unit::TestCase
147
146
  context "level threshold" do
148
147
  setup do
149
148
  @notifier.level = GELF::WARN
149
+ @hash = { '_version' => '1.0', '_short_message' => 'message' }
150
150
  end
151
151
 
152
152
  ['debug', 'DEBUG', :debug].each do |l|
@@ -158,12 +158,12 @@ class TestNotifier < Test::Unit::TestCase
158
158
 
159
159
  should "not send notifications with level below threshold" do
160
160
  @sender.expects(:send_datagrams).never
161
- @notifier.notify!(HASH.merge('_level' => GELF::DEBUG))
161
+ @notifier.notify!(@hash.merge('_level' => GELF::DEBUG))
162
162
  end
163
163
 
164
164
  should "not notifications with level equal or above threshold" do
165
165
  @sender.expects(:send_datagrams).once
166
- @notifier.notify!(HASH.merge('_level' => GELF::WARN))
166
+ @notifier.notify!(@hash.merge('_level' => GELF::WARN))
167
167
  end
168
168
  end
169
169
 
@@ -175,7 +175,7 @@ class TestNotifier < Test::Unit::TestCase
175
175
  should "not send datagrams" do
176
176
  @sender.expects(:send_datagrams).never
177
177
  @notifier.expects(:extract_hash).never
178
- @notifier.notify!(HASH)
178
+ @notifier.notify!({ '_version' => '1.0', '_short_message' => 'message' })
179
179
  end
180
180
 
181
181
  context "and enabled again" do
@@ -185,7 +185,7 @@ class TestNotifier < Test::Unit::TestCase
185
185
 
186
186
  should "send datagrams" do
187
187
  @sender.expects(:send_datagrams)
188
- @notifier.notify!(HASH)
188
+ @notifier.notify!({ '_version' => '1.0', '_short_message' => 'message' })
189
189
  end
190
190
  end
191
191
  end
@@ -194,13 +194,13 @@ class TestNotifier < Test::Unit::TestCase
194
194
  @sender.expects(:send_datagrams).with do |datagrams|
195
195
  datagrams.is_a?(Array) && datagrams[0].is_a?(String)
196
196
  end
197
- @notifier.notify!(HASH)
197
+ @notifier.notify!({ '_version' => '1.0', '_short_message' => 'message' })
198
198
  end
199
199
 
200
200
  GELF::Levels.constants.each do |const|
201
201
  should "call notify with level #{const} from method name" do
202
- @notifier.expects(:notify_with_level).with(GELF.const_get(const), HASH)
203
- @notifier.__send__(const.downcase, HASH)
202
+ @notifier.expects(:notify_with_level).with(GELF.const_get(const), { '_version' => '1.0', '_short_message' => 'message' })
203
+ @notifier.__send__(const.downcase, { '_version' => '1.0', '_short_message' => 'message' })
204
204
  end
205
205
  end
206
206
 
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: -1848230050
4
+ hash: -1420906252
5
5
  prerelease: true
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
9
  - 0
10
- - beta6
11
- version: 1.1.0.beta6
10
+ - gamma1
11
+ version: 1.1.0.gamma1
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-03 00:00:00 +03:00
20
+ date: 2010-12-09 00:00:00 +03:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency