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.



128
129
130
131
132
133
134
135
# File 'lib/logstash/logging/logger.rb', line 128

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



137
138
139
140
141
142
143
144
# File 'lib/logstash/logging/logger.rb', line 137

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



146
147
148
149
150
151
152
153
154
155
156
# File 'lib/logstash/logging/logger.rb', line 146

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