Class: InstStatsd::RequestLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/inst_statsd/request_logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ RequestLogger

Returns a new instance of RequestLogger.



5
6
7
# File 'lib/inst_statsd/request_logger.rb', line 5

def initialize(logger)
  @logger = logger || InstStatsd::NullLogger.new
end

Instance Method Details

#build_log_message(request_stat, header = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/inst_statsd/request_logger.rb', line 13

def build_log_message(request_stat, header = nil)
  header ||= "STATSD"
  message = "[#{header}]"
  request_stat.stats.each do |(name, value)|
    message += " (#{name.to_s.tr(".", "_")}: #{format("%.2f", value)})"
  end
  request_stat.exclusive_stats&.each do |(name, value)|
    message += " (exclusive_#{name.to_s.tr(".", "_")}: #{format("%.2f", value)})"
  end
  message
end

#log(request_stat, header = nil) ⇒ Object



9
10
11
# File 'lib/inst_statsd/request_logger.rb', line 9

def log(request_stat, header = nil)
  @logger.info(build_log_message(request_stat, header))
end