Sha256: 76dd2105ea7e709fc08b40ec471646a4a2b3398a6a491ae4f62c5684ad6992b2

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 KB

Contents

module SemanticLogger
  module Formatters
    class Default < Base
      # Default text log format
      #  Generates logs of the form:
      #    2011-07-19 14:36:15.660235 D [1149:ScriptThreadProcess] Rails -- Hello World
      def call(log, logger)
        # Date & time
        message = time_format.nil? ? '' : "#{format_time(log.time)} "

        # Log level and process info
        message << "#{log.level_to_s} [#{log.process_info}]"

        # Tags
        message << ' ' << log.tags.collect { |tag| "[#{tag}]" }.join(' ') if log.tags && (log.tags.size > 0)

        # Named Tags
        if (named_tags = log.named_tags) && !named_tags.empty?
          list = []
          named_tags.each_pair { |name, value| list << "[#{name}: #{value}]" }
          message << ' ' << list.join(' ')
        end

        # Duration
        message << " (#{log.duration_human})" if log.duration

        # Class / app name
        message << " #{log.name}"

        # Log message
        message << " -- #{log.message}" if log.message

        # Payload
        if payload = log.payload_to_s
          message << ' -- ' << payload
        end

        # Exceptions
        if log.exception
          message << " -- Exception: #{log.exception.class}: #{log.exception.message}\n"
          message << log.backtrace_to_s
        end
        message
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
semantic_logger-4.0.0 lib/semantic_logger/formatters/default.rb
semantic_logger-4.0.0.rc1 lib/semantic_logger/formatters/default.rb
semantic_logger-4.0.0.beta2 lib/semantic_logger/formatters/default.rb
semantic_logger-4.0.0.beta1 lib/semantic_logger/formatters/default.rb