Skip to content

Commit

Permalink
Merge pull request #33 from MBXSystems/hotfix/close-udp
Browse files Browse the repository at this point in the history
Close UDPSocket when closing logger
  • Loading branch information
joschi committed May 6, 2015
2 parents 291d8be + e806eb4 commit 74f0388
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Expand Up @@ -25,7 +25,7 @@ GEM
nokogiri (= 1.5.10)
rake
rdoc
json (1.8.0)
json (1.8.2)
jwt (0.1.8)
multi_json (>= 1.5)
metaclass (0.0.1)
Expand Down
4 changes: 0 additions & 4 deletions lib/gelf/logger.rb
Expand Up @@ -4,10 +4,6 @@ module LoggerCompatibility

attr_accessor :formatter

# Does nothing.
def close
end

# Use it like Logger#add... or better not to use at all.
def add(level, message = nil, progname = nil, &block)
progname ||= default_options['facility']
Expand Down
5 changes: 5 additions & 0 deletions lib/gelf/notifier.rb
Expand Up @@ -98,6 +98,11 @@ def enable
@enabled = true
end

# Closes sender
def close
@sender.close
end

# Same as notify!, but rescues all exceptions (including +ArgumentError+)
# and sends them instead.
def notify(*args)
Expand Down
4 changes: 4 additions & 0 deletions lib/gelf/ruby_sender.rb
Expand Up @@ -16,5 +16,9 @@ def send_datagrams(datagrams)
@socket.send(datagram, 0, host, port)
end
end

def close
@socket.close
end
end
end
8 changes: 8 additions & 0 deletions test/test_logger.rb
Expand Up @@ -209,5 +209,13 @@ class TestLogger < Test::Unit::TestCase
should "have formatter attribute" do
@logger.formatter
end


context "close" do
should "close socket" do
@sender.expects(:close).once
@logger.close
end
end
end
end
7 changes: 7 additions & 0 deletions test/test_notifier.rb
Expand Up @@ -226,6 +226,13 @@ class MyNotifier < GELF::Notifier; end
end
end

context "close" do
should "close sender" do
@sender.expects(:close).once
@notifier.close
end
end

context "when disabled" do
setup do
@notifier.disable
Expand Down

0 comments on commit 74f0388

Please sign in to comment.