gelf 1.2.0.beta1 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - ree
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby
7
+
8
+ notifications:
9
+ irc: "irc.freenode.org#graylog2"
@@ -1,8 +1,6 @@
1
1
  = GELF
2
2
 
3
- This is the new GELF gem written by Alexey Palazhchenko. It is based on the old gem by Lennart Koopmann and allows you to send GELF
4
- messages to Graylog2 server instances. See http://www.graylog2.org/about/gelf for more information about GELF and
5
- http://www.graylog2.org/documentation/libraries for usage examples.
3
+ This is the new GELF gem written by Alexey Palazhchenko. It is based on the old gem by Lennart Koopmann and allows you to send GELF messages to Graylog2 server instances. See http://www.graylog2.org/about/gelf for more information about GELF and http://rdoc.info/github/Graylog2/gelf-rb/master/frames for API documentation.
6
4
 
7
5
  Works with Ruby 1.8.7 and 1.9.2. 1.8.6 is not supported.
8
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0.beta1
1
+ 1.3.1
@@ -4,19 +4,20 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{gelf}
8
- s.version = "1.2.0.beta1"
7
+ s.name = "gelf"
8
+ s.version = "1.3.1"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Alexey Palazhchenko}, %q{Lennart Koopmann}]
12
- s.date = %q{2011-05-23}
13
- s.description = %q{Library to send GELF messages to Graylog2 logging server. Supports plain-text, GELF messages and exceptions.}
14
- s.email = %q{alexey.palazhchenko@gmail.com}
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Alexey Palazhchenko", "Lennart Koopmann"]
12
+ s.date = "2011-10-28"
13
+ s.description = "Library to send GELF messages to Graylog2 logging server. Supports plain-text, GELF messages and exceptions."
14
+ s.email = "alexey.palazhchenko@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
+ ".travis.yml",
20
21
  "CHANGELOG",
21
22
  "LICENSE",
22
23
  "README.rdoc",
@@ -35,10 +36,10 @@ Gem::Specification.new do |s|
35
36
  "test/test_ruby_sender.rb",
36
37
  "test/test_severity.rb"
37
38
  ]
38
- s.homepage = %q{http://github.com/Graylog2/gelf-rb}
39
- s.require_paths = [%q{lib}]
40
- s.rubygems_version = %q{1.8.3}
41
- s.summary = %q{Library to send GELF messages to Graylog2 logging server.}
39
+ s.homepage = "http://github.com/Graylog2/gelf-rb"
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = "1.8.11"
42
+ s.summary = "Library to send GELF messages to Graylog2 logging server."
42
43
 
43
44
  if s.respond_to? :specification_version then
44
45
  s.specification_version = 3
@@ -6,7 +6,7 @@ module GELF
6
6
  attr_accessor :last_chunk_id
7
7
  end
8
8
 
9
- attr_accessor :enabled, :collect_file_and_line
9
+ attr_accessor :enabled, :collect_file_and_line, :rescue_network_errors
10
10
  attr_reader :max_chunk_size, :level, :default_options, :level_mapping
11
11
 
12
12
  # +host+ and +port+ are host/ip and port of graylog2-server.
@@ -18,6 +18,7 @@ module GELF
18
18
 
19
19
  self.level = GELF::DEBUG
20
20
  self.max_chunk_size = max_size
21
+ self.rescue_network_errors = false
21
22
 
22
23
  self.default_options = default_options
23
24
  self.default_options['version'] = SPEC_VERSION
@@ -128,6 +129,8 @@ module GELF
128
129
  private
129
130
  def notify_with_level(message_level, *args)
130
131
  notify_with_level!(message_level, *args)
132
+ rescue SocketError
133
+ raise unless self.rescue_network_errors
131
134
  rescue Exception => exception
132
135
  notify_with_level!(GELF::UNKNOWN, exception)
133
136
  end
@@ -188,7 +191,7 @@ module GELF
188
191
  end
189
192
 
190
193
  def set_timestamp
191
- @hash['timestamp'] = Time.now.utc.to_f
194
+ @hash['timestamp'] = Time.now.utc.to_f if @hash['timestamp'].nil?
192
195
  end
193
196
 
194
197
  def check_presence_of_mandatory_attributes
@@ -203,7 +206,7 @@ module GELF
203
206
  data = serialize_hash
204
207
  datagrams = []
205
208
 
206
- # Maximum total size is 8192 byte for UDP datagram. Split to chunks if bigger. (GELFv2 supports chunking)
209
+ # Maximum total size is 8192 byte for UDP datagram. Split to chunks if bigger. (GELF v1.0 supports chunking)
207
210
  if data.count > @max_chunk_size
208
211
  id = self.class.last_chunk_id += 1
209
212
  msg_id = Digest::MD5.digest("#{Time.now.to_f}-#{id}")[0, 8]
@@ -112,12 +112,18 @@ class TestNotifier < Test::Unit::TestCase
112
112
  assert_equal line + 1, hash['line']
113
113
  end
114
114
 
115
- should "set timestamp" do
115
+ should "set timestamp to current time if not set" do
116
116
  hash = @notifier.__send__(:extract_hash, { 'version' => '1.0', 'short_message' => 'message' })
117
117
  assert_instance_of Float, hash['timestamp']
118
- now = Time.now.utc.to_i
118
+ now = Time.now.utc.to_f
119
119
  assert ((now - 1)..(now + 1)).include?(hash['timestamp'])
120
120
  end
121
+
122
+ should "set timestamp to specified time" do
123
+ timestamp = 1319799449.13765
124
+ hash = @notifier.__send__(:extract_hash, { 'version' => '1.0', 'short_message' => 'message', 'timestamp' => timestamp })
125
+ assert_equal timestamp, hash['timestamp']
126
+ end
121
127
  end
122
128
 
123
129
  context "serialize_hash" do
@@ -125,7 +131,7 @@ class TestNotifier < Test::Unit::TestCase
125
131
  @notifier.level_mapping = :direct
126
132
  @notifier.instance_variable_set('@hash', { 'level' => GELF::WARN, 'field' => 'value' })
127
133
  @data = @notifier.__send__(:serialize_hash)
128
- assert @data.respond_to?(:each)
134
+ assert @data.respond_to?(:each) # Enumerable::Enumerator in 1.8, ::Enumerator in 1.9, so...
129
135
  @deserialized_hash = JSON.parse(Zlib::Inflate.inflate(@data.to_a.pack('C*')))
130
136
  assert_instance_of Hash, @deserialized_hash
131
137
  end
@@ -235,4 +241,19 @@ class TestNotifier < Test::Unit::TestCase
235
241
  assert_nothing_raised { @notifier.notify(:no_short_message => 'too bad') }
236
242
  end
237
243
  end
244
+
245
+ context "with notifier with real sender" do
246
+ setup do
247
+ @notifier = GELF::Notifier.new('no_such_host_321')
248
+ end
249
+
250
+ should "raise exception" do
251
+ assert_raise(SocketError) { @notifier.notify('Hello!') }
252
+ end
253
+
254
+ should "not raise exception if asked" do
255
+ @notifier.rescue_network_errors = true
256
+ assert_nothing_raised { @notifier.notify('Hello!') }
257
+ end
258
+ end
238
259
  end
metadata CHANGED
@@ -1,15 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gelf
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196385
5
- prerelease: 6
4
+ hash: 25
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
- - 2
9
- - 0
10
- - beta
8
+ - 3
11
9
  - 1
12
- version: 1.2.0.beta1
10
+ version: 1.3.1
13
11
  platform: ruby
14
12
  authors:
15
13
  - Alexey Palazhchenko
@@ -18,7 +16,7 @@ autorequire:
18
16
  bindir: bin
19
17
  cert_chain: []
20
18
 
21
- date: 2011-05-23 00:00:00 Z
19
+ date: 2011-10-28 00:00:00 Z
22
20
  dependencies:
23
21
  - !ruby/object:Gem::Dependency
24
22
  name: json
@@ -72,6 +70,7 @@ extra_rdoc_files:
72
70
  - LICENSE
73
71
  - README.rdoc
74
72
  files:
73
+ - .travis.yml
75
74
  - CHANGELOG
76
75
  - LICENSE
77
76
  - README.rdoc
@@ -109,18 +108,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
108
  required_rubygems_version: !ruby/object:Gem::Requirement
110
109
  none: false
111
110
  requirements:
112
- - - ">"
111
+ - - ">="
113
112
  - !ruby/object:Gem::Version
114
- hash: 25
113
+ hash: 3
115
114
  segments:
116
- - 1
117
- - 3
118
- - 1
119
- version: 1.3.1
115
+ - 0
116
+ version: "0"
120
117
  requirements: []
121
118
 
122
119
  rubyforge_project:
123
- rubygems_version: 1.8.3
120
+ rubygems_version: 1.8.11
124
121
  signing_key:
125
122
  specification_version: 3
126
123
  summary: Library to send GELF messages to Graylog2 logging server.