Class: Datadog::Core::Metrics::Logging::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/core/metrics/logging.rb

Overview

Surrogate for Datadog::Statsd to log elsewhere

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger = nil) ⇒ Adapter

Returns a new instance of Adapter.



14
15
16
17
18
19
20
21
22
23
# File 'lib/datadog/core/metrics/logging.rb', line 14

def initialize(logger = nil)
  @logger = logger || Logger.new($stdout).tap do |l|
    l.level = ::Logger::INFO
    l.progname = nil
    l.formatter = proc do |_severity, datetime, _progname, msg|
      stat = JSON.parse(msg[3..-1]) # Trim off leading progname...
      "#{JSON.dump(timestamp: datetime.to_i, message: 'Metric sent.', metric: stat)}\n"
    end
  end
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



12
13
14
# File 'lib/datadog/core/metrics/logging.rb', line 12

def logger
  @logger
end

Instance Method Details

#count(stat, value, options = nil) ⇒ Object



25
26
27
# File 'lib/datadog/core/metrics/logging.rb', line 25

def count(stat, value, options = nil)
  logger.info({ stat: stat, type: :count, value: value, options: options }.to_json)
end

#distribution(stat, value, options = nil) ⇒ Object



29
30
31
# File 'lib/datadog/core/metrics/logging.rb', line 29

def distribution(stat, value, options = nil)
  logger.info({ stat: stat, type: :distribution, value: value, options: options }.to_json)
end

#gauge(stat, value, options = nil) ⇒ Object



37
38
39
# File 'lib/datadog/core/metrics/logging.rb', line 37

def gauge(stat, value, options = nil)
  logger.info({ stat: stat, type: :gauge, value: value, options: options }.to_json)
end

#increment(stat, options = nil) ⇒ Object



33
34
35
# File 'lib/datadog/core/metrics/logging.rb', line 33

def increment(stat, options = nil)
  logger.info({ stat: stat, type: :increment, options: options }.to_json)
end