Sha256: 798580dfe3c6d9e0187aca09e001a0f4239b9987b9fd20b730a0fe88d7f5c800

Contents?: true

Size: 790 Bytes

Versions: 9

Compression:

Stored size: 790 Bytes

Contents

# frozen_string_literal: true

class Logger
  # Default formatter for log messages.
  class Formatter
    Format = "%.1s, [%s #%d] %5s -- %s: %s\n"
    DatetimeFormat = "%Y-%m-%dT%H:%M:%S.%6N"

    attr_accessor :datetime_format

    def initialize
      @datetime_format = nil
    end

    def call(severity, time, progname, msg)
      sprintf(Format, severity, format_datetime(time), Process.pid, severity, progname, msg2str(msg))
    end

  private

    def format_datetime(time)
      time.strftime(@datetime_format || DatetimeFormat)
    end

    def msg2str(msg)
      case msg
      when ::String
        msg
      when ::Exception
        "#{ msg.message } (#{ msg.class })\n#{ msg.backtrace.join("\n") if msg.backtrace }"
      else
        msg.inspect
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
es_cli-0.1.0 vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/lib/logger/formatter.rb
logger-1.6.5 lib/logger/formatter.rb
logger-1.6.4 lib/logger/formatter.rb
logger-1.6.3 lib/logger/formatter.rb
logger-1.6.2 lib/logger/formatter.rb
logger-1.6.1 lib/logger/formatter.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/logger-1.6.0/lib/logger/formatter.rb
logger-1.6.0 lib/logger/formatter.rb
logger-1.5.3 lib/logger/formatter.rb