class Filum::LogFormatter
Public Class Methods
new(options = {})
click to toggle source
# File lib/filum/log_formatter.rb, line 5 def initialize(options = {}) @context_id_length = options.fetch(:context_id_length, 6) @filename_length = options.fetch(:filename_length, 20) end
Public Instance Methods
call(severity, timestamp, progname, msg)
click to toggle source
# File lib/filum/log_formatter.rb, line 10 def call(severity, timestamp, progname, msg) "#{timestamp} #{formatted_thread_id} [#{formatted_context_id}] #{severity.to_s.ljust(5)} | #{formatted_calling_file_and_line} | #{msg}\n" end
Private Instance Methods
calling_code()
click to toggle source
# File lib/filum/log_formatter.rb, line 36 def calling_code caller[5] end
context_id()
click to toggle source
# File lib/filum/log_formatter.rb, line 19 def context_id Thread.current[:context_id].to_s end
formatted_calling_file_and_line()
click to toggle source
# File lib/filum/log_formatter.rb, line 23 def formatted_calling_file_and_line filename_length = @filename_length truncated_filename_length = filename_length - 3 _, file, line = calling_code.match(/([\w\.]+)\:(\d+)\:in /).to_a file = "#{file[0,truncated_filename_length]}..." if file.length >= filename_length "#{file}:#{line.ljust(3)}".ljust(filename_length + 4) end
formatted_context_id()
click to toggle source
# File lib/filum/log_formatter.rb, line 15 def formatted_context_id context_id.ljust(@context_id_length) end
formatted_thread_id()
click to toggle source
# File lib/filum/log_formatter.rb, line 32 def formatted_thread_id "t-#{thread_id}".ljust(12) end
thread_id()
click to toggle source
# File lib/filum/log_formatter.rb, line 40 def thread_id Thread.current.object_id end