class DohLog::Event

Attributes

exception[RW]
extras[RW]
location[RW]
msg[RW]
severity[RW]
time[RW]

Public Class Methods

new(severity, msg, location = '', exception = nil) click to toggle source
# File lib/dohlog/event.rb, line 8
def initialize(severity, msg, location = '', exception = nil)
  @severity, @msg, @location, @exception = severity, msg, location, exception
  @extras = {}
  @time = Time.now
end

Public Instance Methods

call_stack() click to toggle source
# File lib/dohlog/event.rb, line 36
def call_stack
  if @exception then @exception.backtrace else caller end
end
datetime_text() click to toggle source
# File lib/dohlog/event.rb, line 22
def datetime_text
  @time.strftime("%Y-%m-%d %H:%M:%S.") << "%03d" % (@time.usec / 1000)
end
exception_text() click to toggle source
# File lib/dohlog/event.rb, line 26
def exception_text
  return '' unless @exception
  if @exception.backtrace
    stack = @exception.backtrace.collect { |elem| "=> #{elem}" }.join("\n")
  else
    stack = 'no backtrace available...?'
  end
  "=> exception: #{@exception.class} - #{@exception.message}\n=> stack:\n#{stack}"
end
severity_text() click to toggle source
# File lib/dohlog/event.rb, line 14
def severity_text
  DohLog::severity_text(@severity)
end
summary() click to toggle source
# File lib/dohlog/event.rb, line 40
def summary
  if @extras.empty?
    extra_str = ''
  else
    extra_ary = []
    @extras.each_pair do |key, value|
      extra_ary << "#{key}: #{value}"
    end
    extra_str = "<#{extra_ary.join(', ')}> "
  end
  threadstr = ":#{Thread.current.object_id}" if DohLog.should_log_thread_ids
  "#{datetime_text} <#{Process.pid}#{threadstr}> [#{severity_text}] (#{location}) #{extra_str}: #{msg}"
end
time_text() click to toggle source
# File lib/dohlog/event.rb, line 18
def time_text
  @time.strftime("%H:%M:%S.") << "%03d" % (@time.usec / 1000)
end