Sha256: 25a719b7db7690c4a9d75d4075e33b4633366498659c5060fa523f18cc3b8867

Contents?: true

Size: 951 Bytes

Versions: 21

Compression:

Stored size: 951 Bytes

Contents

require 'logger'

module Madvertise
  module Logging

    ##
    # DocumentLogger is a Logger compliant class that keeps a structured
    # document per log message in memory.
    #
    class DocumentLogger < ::Logger

      attr_accessor :attrs
      attr_accessor :messages

      def initialize
        super(nil)
        @messages = []
        @attrs = {}
      end

      def add(severity, message = nil, progname = nil, &block)
        severity ||= UNKNOWN
        if severity < @level
          return true
        end

        progname ||= @progname

        if message.nil?
          if block_given?
            message = yield
          else
            message = progname
            progname = @progname
          end
        end

        @messages << @attrs.merge({
          severity: severity,
          time: Time.now.to_f,
          progname: progname,
          message: message,
        })

        true
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
madvertise-logging-1.3.0 lib/madvertise/logging/document_logger.rb
madvertise-logging-1.3.0-java lib/madvertise/logging/document_logger.rb
madvertise-logging-1.2.1 lib/madvertise/logging/document_logger.rb
madvertise-logging-1.2.1-java lib/madvertise/logging/document_logger.rb
madvertise-logging-1.2.0 lib/madvertise/logging/document_logger.rb
madvertise-logging-1.1.2 lib/madvertise/logging/document_logger.rb
madvertise-logging-1.1.1 lib/madvertise/logging/document_logger.rb
madvertise-logging-1.1.0 lib/madvertise/logging/document_logger.rb
madvertise-logging-1.0.3 lib/madvertise/logging/document_logger.rb
madvertise-logging-1.0.2 lib/madvertise/logging/document_logger.rb
madvertise-logging-1.0.1 lib/madvertise/logging/document_logger.rb
madvertise-logging-1.0.0 lib/madvertise/logging/document_logger.rb
madvertise-logging-1.0.0.rc4 lib/madvertise/logging/document_logger.rb
madvertise-logging-1.0.0.rc3 lib/madvertise/logging/document_logger.rb
madvertise-logging-1.0.0.rc2 lib/madvertise/logging/document_logger.rb
madvertise-logging-1.0.0.rc1 lib/madvertise/logging/document_logger.rb
madvertise-logging-0.9.4 lib/madvertise/logging/document_logger.rb
madvertise-logging-0.9.3 lib/madvertise/logging/document_logger.rb
madvertise-logging-0.9.2 lib/madvertise/logging/document_logger.rb
madvertise-logging-0.9.1 lib/madvertise/logging/document_logger.rb