Class: Sherlog::Entry

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Entry

Returns a new instance of Entry.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sherlog_holmes/entry.rb', line 28

def initialize(params = {})
  params = params.dup
  @time = params.delete :time if params[:time]
  @level = params.delete :level if params[:level]
  @category = params.delete :category if params[:category]
  @origin = params.delete :origin if params[:origin]
  @message = params.delete :message if params[:message]
  @raw_content = params.delete :raw_content if params[:raw_content]
  @exceptions = [params.delete(:exception)] if params[:exception]
  @exceptions ||= params.delete(:exceptions) if params[:exceptions]
  @exceptions ||= []
  @stacktrace = []
  @custom_attributes = params
end

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



26
27
28
# File 'lib/sherlog_holmes/entry.rb', line 26

def category
  @category
end

#exceptionsObject

Returns the value of attribute exceptions.



26
27
28
# File 'lib/sherlog_holmes/entry.rb', line 26

def exceptions
  @exceptions
end

#levelObject

Returns the value of attribute level.



26
27
28
# File 'lib/sherlog_holmes/entry.rb', line 26

def level
  @level
end

#messageObject

Returns the value of attribute message.



26
27
28
# File 'lib/sherlog_holmes/entry.rb', line 26

def message
  @message
end

#originObject

Returns the value of attribute origin.



26
27
28
# File 'lib/sherlog_holmes/entry.rb', line 26

def origin
  @origin
end

#raw_contentObject

Returns the value of attribute raw_content.



26
27
28
# File 'lib/sherlog_holmes/entry.rb', line 26

def raw_content
  @raw_content
end

#stacktraceObject

Returns the value of attribute stacktrace.



26
27
28
# File 'lib/sherlog_holmes/entry.rb', line 26

def stacktrace
  @stacktrace
end

#timeObject

Returns the value of attribute time.



26
27
28
# File 'lib/sherlog_holmes/entry.rb', line 26

def time
  @time
end

Instance Method Details

#<<(line) ⇒ Object



51
52
53
# File 'lib/sherlog_holmes/entry.rb', line 51

def <<(line)
  @message << $/ << line
end

#[](custom_attribute) ⇒ Object



55
56
57
# File 'lib/sherlog_holmes/entry.rb', line 55

def [](custom_attribute)
  @custom_attributes[custom_attribute.to_s] or @custom_attributes[custom_attribute.to_sym]
end

#exceptionObject



47
48
49
# File 'lib/sherlog_holmes/entry.rb', line 47

def exception
  @exceptions.first
end

#exception?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/sherlog_holmes/entry.rb', line 43

def exception?
  !@exceptions.empty?
end

#to_sObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/sherlog_holmes/entry.rb', line 59

def to_s
  format = []
  params = []
  format << '%s' && params << time if time
  format << '%s' && params << level.to_s.ljust(7) if level
  format << '[%s]' && params << category if category
  format << '(%s)' && params << origin if origin
  format << '%s' && params << message if message
  string = format.join(' ') % params
  ([string] + @stacktrace).join($/)
end