Sha256: b32f656ba2a8842f503207fed51b07ba2ebb355fddf142627c4be67e23af55c4

Contents?: true

Size: 776 Bytes

Versions: 4

Compression:

Stored size: 776 Bytes

Contents

require 'logger'
require 'time'
require 'socket'

module Ougai
  module Formatters
    class Base < Logger::Formatter
      attr_accessor :trace_indent, :trace_max_lines

      def initialize(app_name = nil, hostname = nil)
        @app_name = app_name || File.basename($0, ".rb")
        @hostname = hostname || Socket.gethostname
        @trace_indent = 2
        @trace_max_lines = 100
      end

      def serialize_exc(ex)
        err = {
          name: ex.class.name,
          message: ex.to_s
        }
        if ex.backtrace
          err[:stack] = serialize_trace(ex.backtrace)
        end
        err
      end

      def serialize_trace(trace)
        sp = "\n" + ' ' * @trace_indent
        trace.slice(0, @trace_max_lines).join(sp)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ougai-0.7.3 lib/ougai/formatters/base.rb
ougai-0.7.2 lib/ougai/formatters/base.rb
ougai-0.7.1 lib/ougai/formatters/base.rb
ougai-0.7.0 lib/ougai/formatters/base.rb