Class: Logfoo::ExceptionEntry

Inherits:
Struct
  • Object
show all
Defined in:
lib/logfoo/entry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#exceptionObject

Returns the value of attribute exception

Returns:

  • (Object)

    the current value of exception



17
18
19
# File 'lib/logfoo/entry.rb', line 17

def exception
  @exception
end

#levelObject

Returns the value of attribute level

Returns:

  • (Object)

    the current value of level



17
18
19
# File 'lib/logfoo/entry.rb', line 17

def level
  @level
end

#logger_nameObject

Returns the value of attribute logger_name

Returns:

  • (Object)

    the current value of logger_name



17
18
19
# File 'lib/logfoo/entry.rb', line 17

def logger_name
  @logger_name
end

#payloadObject

Returns the value of attribute payload

Returns:

  • (Object)

    the current value of payload



17
18
19
# File 'lib/logfoo/entry.rb', line 17

def payload
  @payload
end

#threadObject

Returns the value of attribute thread

Returns:

  • (Object)

    the current value of thread



17
18
19
# File 'lib/logfoo/entry.rb', line 17

def thread
  @thread
end

#timeObject

Returns the value of attribute time

Returns:

  • (Object)

    the current value of time



17
18
19
# File 'lib/logfoo/entry.rb', line 17

def time
  @time
end

Class Method Details

.build(logger_name, ex, payload = nil, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/logfoo/entry.rb', line 19

def build(logger_name, ex, payload = nil, options = {})
  self.new(
    options[:level],
    Time.now,
    logger_name,
    ex,
    payload,
    Thread.current.object_id
  )
end

Instance Method Details

#to_hObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/logfoo/entry.rb', line 31

def to_h
  {
    level:  level || :error,
    time:   time  || Time.now,
    msg:    exception.message,
    logger: logger_name,
    err:    exception.class.to_s,
  }.merge!(
    payload || {}
  ).merge!(
    thread:     thread,
    stacktrace: exception.backtrace,
  )
end