Class: DohLog::Event

Inherits:
Object show all
Defined in:
lib/dohlog/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(severity, msg, location = '', exception = nil) ⇒ Event

Returns a new instance of Event.



8
9
10
11
12
# 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

Instance Attribute Details

#exceptionObject

Returns the value of attribute exception.



6
7
8
# File 'lib/dohlog/event.rb', line 6

def exception
  @exception
end

#extrasObject

Returns the value of attribute extras.



6
7
8
# File 'lib/dohlog/event.rb', line 6

def extras
  @extras
end

#locationObject

Returns the value of attribute location.



6
7
8
# File 'lib/dohlog/event.rb', line 6

def location
  @location
end

#msgObject

Returns the value of attribute msg.



6
7
8
# File 'lib/dohlog/event.rb', line 6

def msg
  @msg
end

#severityObject

Returns the value of attribute severity.



6
7
8
# File 'lib/dohlog/event.rb', line 6

def severity
  @severity
end

#timeObject

Returns the value of attribute time.



6
7
8
# File 'lib/dohlog/event.rb', line 6

def time
  @time
end

Instance Method Details

#call_stackObject



36
37
38
# File 'lib/dohlog/event.rb', line 36

def call_stack
  if @exception then @exception.backtrace else caller end
end

#datetime_textObject



22
23
24
# File 'lib/dohlog/event.rb', line 22

def datetime_text
  @time.strftime("%Y-%m-%d %H:%M:%S.") << "%03d" % (@time.usec / 1000)
end

#exception_textObject



26
27
28
29
30
31
32
33
34
# 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_textObject



14
15
16
# File 'lib/dohlog/event.rb', line 14

def severity_text
  DohLog::severity_text(@severity)
end

#summaryObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# 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_textObject



18
19
20
# File 'lib/dohlog/event.rb', line 18

def time_text
  @time.strftime("%H:%M:%S.") << "%03d" % (@time.usec / 1000)
end