Skip to content

Commit

Permalink
Merge branch 'release/1.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi committed Oct 28, 2011
2 parents 51a2ec4 + 31fd50f commit f277cd3
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 46 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rvm:
- 1.8.7
- ree
- 1.9.2
- 1.9.3
- jruby

notifications:
irc: "irc.freenode.org#graylog2"
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.0
1.3.1
64 changes: 28 additions & 36 deletions gelf.gemspec
Original file line number Diff line number Diff line change
@@ -1,53 +1,45 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{gelf}
s.version = "1.3.0"
s.name = "gelf"
s.version = "1.3.1"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Alexey Palazhchenko", "Lennart Koopmann"]
s.date = %q{2011-07-27}
s.description = %q{Library to send GELF messages to Graylog2 logging server. Supports plain-text, GELF messages and exceptions.}
s.email = %q{[email protected]}
s.date = "2011-10-28"
s.description = "Library to send GELF messages to Graylog2 logging server. Supports plain-text, GELF messages and exceptions."
s.email = "[email protected]"
s.extra_rdoc_files = [
"LICENSE",
"README.rdoc"
"README.rdoc"
]
s.files = [
".gitignore",
"CHANGELOG",
"LICENSE",
"README.rdoc",
"Rakefile",
"VERSION",
"benchmarks/notifier.rb",
"gelf.gemspec",
"lib/gelf.rb",
"lib/gelf/logger.rb",
"lib/gelf/notifier.rb",
"lib/gelf/ruby_sender.rb",
"lib/gelf/severity.rb",
"test/helper.rb",
"test/test_logger.rb",
"test/test_notifier.rb",
"test/test_ruby_sender.rb",
"test/test_severity.rb"
]
s.homepage = %q{http://github.com/Graylog2/gelf-rb}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.4.1}
s.summary = %q{Library to send GELF messages to Graylog2 logging server.}
s.test_files = [
".travis.yml",
"CHANGELOG",
"LICENSE",
"README.rdoc",
"Rakefile",
"VERSION",
"benchmarks/notifier.rb",
"gelf.gemspec",
"lib/gelf.rb",
"lib/gelf/logger.rb",
"lib/gelf/notifier.rb",
"lib/gelf/ruby_sender.rb",
"lib/gelf/severity.rb",
"test/helper.rb",
"test/test_logger.rb",
"test/test_notifier.rb",
"test/test_ruby_sender.rb",
"test/test_logger.rb",
"test/test_notifier.rb",
"test/test_severity.rb",
"test/helper.rb"
"test/test_severity.rb"
]
s.homepage = "http://github.com/Graylog2/gelf-rb"
s.require_paths = ["lib"]
s.rubygems_version = "1.8.11"
s.summary = "Library to send GELF messages to Graylog2 logging server."

if s.respond_to? :specification_version then
s.specification_version = 3
Expand Down
7 changes: 5 additions & 2 deletions lib/gelf/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class << self
attr_accessor :last_chunk_id
end

attr_accessor :enabled, :collect_file_and_line
attr_accessor :enabled, :collect_file_and_line, :rescue_network_errors
attr_reader :max_chunk_size, :level, :default_options, :level_mapping

# +host+ and +port+ are host/ip and port of graylog2-server.
Expand All @@ -18,6 +18,7 @@ def initialize(host = 'localhost', port = 12201, max_size = 'WAN', default_optio

self.level = GELF::DEBUG
self.max_chunk_size = max_size
self.rescue_network_errors = false

self.default_options = default_options
self.default_options['version'] = SPEC_VERSION
Expand Down Expand Up @@ -128,6 +129,8 @@ def #{const.downcase}(*args) # def debug(*args)
private
def notify_with_level(message_level, *args)
notify_with_level!(message_level, *args)
rescue SocketError
raise unless self.rescue_network_errors
rescue Exception => exception
notify_with_level!(GELF::UNKNOWN, exception)
end
Expand Down Expand Up @@ -203,7 +206,7 @@ def datagrams_from_hash
data = serialize_hash
datagrams = []

# Maximum total size is 8192 byte for UDP datagram. Split to chunks if bigger. (GELFv2 supports chunking)
# Maximum total size is 8192 byte for UDP datagram. Split to chunks if bigger. (GELF v1.0 supports chunking)
if data.count > @max_chunk_size
id = self.class.last_chunk_id += 1
msg_id = Digest::MD5.digest("#{Time.now.to_f}-#{id}")[0, 8]
Expand Down
27 changes: 20 additions & 7 deletions test/test_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,18 @@ class TestNotifier < Test::Unit::TestCase
end

should "set timestamp to specified time" do
date = Time.now.utc-9001.to_f
hash = @notifier.__send__(:extract_hash, { 'version' => '1.0', 'short_message' => 'message', 'timestamp' => date })
assert_equal date, hash['timestamp']
timestamp = 1319799449.13765
hash = @notifier.__send__(:extract_hash, { 'version' => '1.0', 'short_message' => 'message', 'timestamp' => timestamp })
assert_equal timestamp, hash['timestamp']
end
end

context "serialize_hash" do
setup do
@notifier.level_mapping = :direct
@date = Time.now.utc-9001.to_f
@notifier.instance_variable_set('@hash', { 'level' => GELF::WARN, 'field' => 'value', 'timestamp' => @date })
@notifier.instance_variable_set('@hash', { 'level' => GELF::WARN, 'field' => 'value' })
@data = @notifier.__send__(:serialize_hash)
assert @data.respond_to?(:each)
assert @data.respond_to?(:each) # Enumerable::Enumerator in 1.8, ::Enumerator in 1.9, so...
@deserialized_hash = JSON.parse(Zlib::Inflate.inflate(@data.to_a.pack('C*')))
assert_instance_of Hash, @deserialized_hash
end
Expand All @@ -141,7 +140,6 @@ class TestNotifier < Test::Unit::TestCase
assert_not_equal GELF::WARN, @deserialized_hash['level']
assert_not_equal GELF::LOGGER_MAPPING[GELF::WARN], @deserialized_hash['level']
assert_equal GELF::DIRECT_MAPPING[GELF::WARN], @deserialized_hash['level']
assert_equal @date.to_s, @deserialized_hash['timestamp']
end
end

Expand Down Expand Up @@ -243,4 +241,19 @@ class TestNotifier < Test::Unit::TestCase
assert_nothing_raised { @notifier.notify(:no_short_message => 'too bad') }
end
end

context "with notifier with real sender" do
setup do
@notifier = GELF::Notifier.new('no_such_host_321')
end

should "raise exception" do
assert_raise(SocketError) { @notifier.notify('Hello!') }
end

should "not raise exception if asked" do
@notifier.rescue_network_errors = true
assert_nothing_raised { @notifier.notify('Hello!') }
end
end
end

0 comments on commit f277cd3

Please sign in to comment.