Class: LogStash::Logging::SlowLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/logging/logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, warn_threshold, info_threshold, debug_threshold, trace_threshold) ⇒ SlowLogger

Returns a new instance of SlowLogger.



96
97
98
99
100
101
102
103
# File 'lib/logstash/logging/logger.rb', line 96

def initialize(name, warn_threshold, info_threshold, debug_threshold, trace_threshold)
  slowlog_name = ["slowlog", name].join('.')
  @slowlogger = LogManager.getLogger(slowlog_name)
  @warn_threshold = warn_threshold
  @info_threshold = info_threshold
  @debug_threshold = debug_threshold
  @trace_threshold = trace_threshold
end

Instance Method Details

#as_data(plugin_params, event, took_in_nanos) ⇒ Object



105
106
107
108
109
110
111
112
# File 'lib/logstash/logging/logger.rb', line 105

def as_data(plugin_params, event, took_in_nanos)
  {
    :plugin_params => plugin_params,
    :took_in_nanos => took_in_nanos,
    :took_in_millis => took_in_nanos / 1000000,
    :event => event.to_json
  }
end

#on_event(message, plugin_params, event, took_in_nanos) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/logstash/logging/logger.rb', line 114

def on_event(message, plugin_params, event, took_in_nanos)
  if @warn_threshold >= 0 and took_in_nanos > @warn_threshold
    @slowlogger.warn(message, as_data(plugin_params, event, took_in_nanos))
  elsif @info_threshold >= 0 and took_in_nanos > @info_threshold
    @slowlogger.info(message, as_data(plugin_params, event, took_in_nanos))
  elsif @debug_threshold >= 0 and took_in_nanos > @debug_threshold
    @slowlogger.debug(message, as_data(plugin_params, event, took_in_nanos))
  elsif @trace_threshold >= 0 and took_in_nanos > @trace_threshold
    @slowlogger.trace(message, as_data(plugin_params, event, took_in_nanos))
  end
end