Sha256: ec5c25f3e24e4a7c678d3d15138f0c4ae4f3af76f45eba8075024556ca3e1580

Contents?: true

Size: 571 Bytes

Versions: 3

Compression:

Stored size: 571 Bytes

Contents

# frozen_string_literal: true

require "logger"
require "digest/md5"
require "English"

module ThreadedLogging
  def self.thread_fingerprint
    Digest::MD5.hexdigest([Thread.current.object_id, $PID].join)[0...8]
  end

  def call(severity, time, _progname, msg)
    time_string = time.strftime("%Y-%m-%dT%H:%M:%S.%6N")
    metadata = "#{severity[0]} [#{time_string}] ##{ThreadedLogging.thread_fingerprint}:"

    message = +""
    msg.to_s.lines.each { |line| message << "#{metadata} #{line}" }
    "#{message}\n"
  end
end

::Logger::Formatter.prepend(ThreadedLogging)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
threaded_logging-0.2.1.16 lib/threaded_logging.rb
threaded_logging-0.2.1.15 lib/threaded_logging.rb
threaded_logging-0.2.1 lib/threaded_logging.rb