Skip to content

Commit

Permalink
Ignore socket errors even if logger is not set.
Browse files Browse the repository at this point in the history
Closes jeremy#2
  • Loading branch information
j-manu authored and jeremy committed May 30, 2012
1 parent 9c15b2b commit fecfbc5
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions lib/statsd.rb
Expand Up @@ -25,14 +25,7 @@ class Statsd


class << self class << self
# Set to a standard logger instance to enable debug logging. # Set to a standard logger instance to enable debug logging.
attr_reader :logger attr_accessor :logger

def logger=(logger) #:nodoc:
@logger = logger

# Only include logging behavior if a logger is set.
include Logging
end
end end


# @param [String] host your statsd host # @param [String] host your statsd host
Expand Down Expand Up @@ -136,19 +129,10 @@ def send_stats(stat, delta, type, sample_rate=1)
end end
end end


module Sending def send_to_socket(message)
def send_to_socket(message) self.class.logger.debug { "Statsd: #{message}" } if self.class.logger
@socket.send(message, 0, @host, @port) @socket.send(message, 0, @host, @port)
end rescue => boom
end self.class.logger.error { "Statsd: #{boom.class} #{boom}" } if self.class.logger
include Sending

module Logging
def send_to_socket(message)
self.class.logger.debug {"Statsd: #{message}"}
super
rescue => boom
self.class.logger.error {"Statsd: #{boom.class} #{boom}"}
end
end end
end end

0 comments on commit fecfbc5

Please sign in to comment.