Sha256: 04ca99d46be330e24f3a54eda19afd42dc017cfc3f6eb7dfaf0105c33143c5dc

Contents?: true

Size: 1.05 KB

Versions: 17

Compression:

Stored size: 1.05 KB

Contents

require "cabin"

# Wrap Ruby stdlib's logger. This allows you to output to a normal ruby logger
# with Cabin. Since Ruby's Logger has a love for strings alone, this
# wrapper will convert the data/event to ruby inspect format before sending it
# to Logger.
class Cabin::Outputs::StdlibLogger
  public
  def initialize(logger)
    @logger = logger
    @logger.level = logger.class::DEBUG
  end # def initialize

  # Receive an event
  public
  def <<(event)
    if !event.include?(:level)
      event[:level] = :info
    end
    if event[:level].is_a?(Symbol)
      method = event[:level]
    else
      method = event[:level].downcase.to_sym || :info
    end
    event.delete(:level)

    data = event.clone
    # delete things from the 'data' portion that's not really data.
    data.delete(:message)
    data.delete(:timestamp)
    message = "#{event[:message]} #{data.inspect}"

    #p [@logger.level, logger.class::DEBUG]
    # This will call @logger.info(data) or something similar.
    @logger.send(method, message)
  end # def <<
end # class Cabin::Outputs::StdlibLogger

Version data entries

17 entries across 15 versions & 6 rubygems

Version Path
logstash-filter-zabbix-0.1.2 vendor/bundle/jruby/1.9/gems/cabin-0.8.1/lib/cabin/outputs/stdlib-logger.rb
logstash-filter-zabbix-0.1.1 vendor/bundle/jruby/1.9/gems/cabin-0.8.1/lib/cabin/outputs/stdlib-logger.rb
ivanvc-logstash-input-s3-3.1.1.4 vendor/local/gems/cabin-0.8.1/lib/cabin/outputs/stdlib-logger.rb
ivanvc-logstash-input-s3-3.1.1.3 vendor/local/gems/cabin-0.8.1/lib/cabin/outputs/stdlib-logger.rb
ivanvc-logstash-input-s3-3.1.1.2 vendor/local/gems/cabin-0.8.1/lib/cabin/outputs/stdlib-logger.rb
cabin-0.9.0 lib/cabin/outputs/stdlib-logger.rb
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/cabin-0.7.1/lib/cabin/outputs/stdlib-logger.rb
cabin-0.8.1 lib/cabin/outputs/stdlib-logger.rb
cabin-0.8.0 lib/cabin/outputs/stdlib-logger.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/cabin-0.7.1/lib/cabin/outputs/stdlib-logger.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/cabin-0.7.2/lib/cabin/outputs/stdlib-logger.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/logstash-codec-json-2.0.3/vendor/gems/cabin-0.7.2/lib/cabin/outputs/stdlib-logger.rb
logstash-codec-json-2.0.3 vendor/gems/cabin-0.7.2/lib/cabin/outputs/stdlib-logger.rb
cabin-0.7.2 lib/cabin/outputs/stdlib-logger.rb
logstash-input-beats-0.9.2 vendor/jruby/1.9/gems/cabin-0.7.1/lib/cabin/outputs/stdlib-logger.rb
logstash-input-beats-0.9.1 vendor/jruby/1.9/gems/cabin-0.7.1/lib/cabin/outputs/stdlib-logger.rb
cabin-0.7.1 lib/cabin/outputs/stdlib-logger.rb