Sha256: a63afacf7adabb3c579d45118eb1fa7ce9d4e4eea09a403cf7ed3d7a57121819

Contents?: true

Size: 801 Bytes

Versions: 12

Compression:

Stored size: 801 Bytes

Contents

# frozen_string_literal: true

class LogFormatter
  LOG_FORMAT = "%s, %s [%s/%s/%s] %s\n"
  DEFAULT_DATETIME_FORMAT = '%F %T.%N'

  attr_accessor :datetime_format

  def initialize
    @datetime_format = nil
  end

  def call(severity, time, progname, message)
    format(LOG_FORMAT, severity[0..0], format_datetime(time), "0x#{Async::Task.current?&.object_id&.to_s(16)}", "0x#{Fiber.current.object_id.to_s(16)}", progname, format_message(message))
  end

  private

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

  def format_message(message)
    case message
    when ::String
      message
    when ::Exception
      "<#{message.class}>:#{message.message}\n#{(message.backtrace || []).join("\n")}"
    else
      message.inspect
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
libvirt_ffi-0.8.0 test_usage/support/log_formatter.rb
libvirt_ffi-0.7.0 test_usage/support/log_formatter.rb
libvirt_ffi-0.6.2 test_usage/support/log_formatter.rb
libvirt_ffi-0.6.1 test_usage/support/log_formatter.rb
libvirt_ffi-0.6.0 test_usage/support/log_formatter.rb
libvirt_ffi-0.5.6 test_usage/support/log_formatter.rb
libvirt_ffi-0.5.5 test_usage/support/log_formatter.rb
libvirt_ffi-0.5.4 test_usage/support/log_formatter.rb
libvirt_ffi-0.5.3 test_usage/support/log_formatter.rb
libvirt_ffi-0.5.2 test_usage/support/log_formatter.rb
libvirt_ffi-0.5.1 test_usage/support/log_formatter.rb
libvirt_ffi-0.5.0 test_usage/support/log_formatter.rb