Browse files

Add debug logging abilities

Setting Statsd.logger to any std logger instance will log all stats using a log.debug block.
  • Loading branch information...
1 parent 7937cfb commit 55ce9b72a8b9d8edec93b774f6eae55ee0079cdb @raykrueger raykrueger committed Jun 23, 2011
Showing with 10 additions and 1 deletion.
  1. +10 −1 lib/statsd.rb
View
11 lib/statsd.rb
@@ -10,6 +10,10 @@
# statsd.timing 'glork', 320
class Statsd
attr_accessor :namespace
+
+ class << self
+ attr_accessor :logger
+ end
# @param [String] host your statsd host
# @param [Integer] port your statsd port
@@ -50,7 +54,12 @@ def sampled(sample_rate)
def send(stat, delta, type, sample_rate)
prefix = "#{@namespace}." unless @namespace.nil?
- sampled(sample_rate) { socket.send("#{prefix}#{stat}:#{delta}|#{type}#{'|@' << sample_rate.to_s if sample_rate < 1}", 0, @host, @port) }
+ sampled(sample_rate) { send_to_socket("#{prefix}#{stat}:#{delta}|#{type}#{'|@' << sample_rate.to_s if sample_rate < 1}") }
+ end
+
+ def send_to_socket(message)
+ self.class.logger.debug {"Statsd: #{message}"} if self.class.logger
+ socket.send(message, 0, @host, @port)
end
def socket; @socket ||= UDPSocket.new end

0 comments on commit 55ce9b7

Please sign in to comment.