Class: Logbert::Message
- Inherits:
-
Object
- Object
- Logbert::Message
- Defined in:
- lib/logbert/message.rb
Instance Attribute Summary collapse
-
#content_proc ⇒ Object
readonly
Returns the value of attribute content_proc.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
- .convert_exception(exc) ⇒ Object
- .create(logger, level, exception, options, content = nil, &content_proc) ⇒ Object
- .from_json(json_msg) ⇒ Object
Instance Method Summary collapse
-
#content ⇒ Object
Returns the content.
-
#initialize(logger, level, time, pid, exception, options, content = nil, &content_proc) ⇒ Message
constructor
A new instance of Message.
- #to_json ⇒ Object
Constructor Details
#initialize(logger, level, time, pid, exception, options, content = nil, &content_proc) ⇒ Message
Returns a new instance of Message.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/logbert/message.rb', line 6 def initialize(logger, level, time, pid, exception, , content = nil, &content_proc) @logger = logger @level = level @time = time @pid = pid @exception = exception @options = @content = content @content_proc = content_proc end |
Instance Attribute Details
#content_proc ⇒ Object (readonly)
Returns the value of attribute content_proc.
4 5 6 |
# File 'lib/logbert/message.rb', line 4 def content_proc @content_proc end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
4 5 6 |
# File 'lib/logbert/message.rb', line 4 def exception @exception end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
4 5 6 |
# File 'lib/logbert/message.rb', line 4 def level @level end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
4 5 6 |
# File 'lib/logbert/message.rb', line 4 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/logbert/message.rb', line 4 def @options end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
4 5 6 |
# File 'lib/logbert/message.rb', line 4 def pid @pid end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
4 5 6 |
# File 'lib/logbert/message.rb', line 4 def time @time end |
Class Method Details
.convert_exception(exc) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/logbert/message.rb', line 41 def self.convert_exception(exc) if exc.is_a? Exception return { exc_class: exc.exception.class, exc_message: exc.exception., exc_backtrace: exc.exception.backtrace } else return exc end end |
.create(logger, level, exception, options, content = nil, &content_proc) ⇒ Object
18 19 20 |
# File 'lib/logbert/message.rb', line 18 def self.create(logger, level, exception, , content = nil, &content_proc) Message.new logger, level, Time.now, Process.pid, Message.convert_exception(exception), , content, &content_proc end |
.from_json(json_msg) ⇒ Object
22 23 24 25 26 |
# File 'lib/logbert/message.rb', line 22 def self.from_json(json_msg) l = Level.new(json_msg[:level_name], json_msg[:level_value]) # note: the exception key contains a hash-level representation of an exception Message.create(json_msg[:logger], l, json_msg[:exception], json_msg[:options], json_msg[:content], json_msg[:content_proc]) end |
Instance Method Details
#content ⇒ Object
Returns the content. If the content has not been created yet, then call @content_proc and save the value.
55 56 57 58 59 60 61 62 63 |
# File 'lib/logbert/message.rb', line 55 def content @content ||= begin if @content_proc @content_proc.call.to_s else "" end end end |
#to_json ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/logbert/message.rb', line 28 def to_json return { logger: @logger.to_s, level: {level_value: @level.value, level_name: @level.name}, time: @time.to_s, pid: @pid, exception: @exception, options: @options, content: self.content, content_proc: nil } end |