Class: NexusSemanticLogger::LoggerMetricsSubscriber
- Inherits:
-
SemanticLogger::Subscriber
- Object
- SemanticLogger::Subscriber
- NexusSemanticLogger::LoggerMetricsSubscriber
- Defined in:
- lib/nexus_semantic_logger/logger_metrics_subscriber.rb
Overview
Sends SemanticLogger metrics to statsd. See logger.rocketjob.io/metrics.html Based on github.com/reidmorrison/semantic_logger/blob/master/lib/semantic_logger/metric/statsd.rb
Instance Method Summary collapse
- #call(log) ⇒ Object
- #log(log) ⇒ Object
-
#should_log?(log) ⇒ Boolean
Only forward log entries that contain metrics.
Instance Method Details
#call(log) ⇒ Object
9 10 11 |
# File 'lib/nexus_semantic_logger/logger_metrics_subscriber.rb', line 9 def call(log) log(log) if should_log?(log) end |
#log(log) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/nexus_semantic_logger/logger_metrics_subscriber.rb', line 13 def log(log) metric = log.metric = log.payload.nil? ? nil : [] log.payload&.each_pair { |key, value| << "#{key}:#{value}" } if (duration = log.duration) NexusSemanticLogger.metrics.timing(metric, duration, tags: ) else amount = (log.metric_amount || 1).round if amount.negative? NexusSemanticLogger.metrics.decrement(metric, tags: ) else NexusSemanticLogger.metrics.increment(metric, tags: ) end end end |
#should_log?(log) ⇒ Boolean
Only forward log entries that contain metrics.
30 31 32 33 |
# File 'lib/nexus_semantic_logger/logger_metrics_subscriber.rb', line 30 def should_log?(log) # Does not support metrics with dimensions. log.metric && !log.dimensions && meets_log_level?(log) && !filtered?(log) end |