Class: Nyanko::Logger::Message
- Inherits:
-
Object
- Object
- Nyanko::Logger::Message
- Defined in:
- lib/nyanko/logger.rb
Constant Summary collapse
- PREFIX =
" [Nyanko]"
Instance Method Summary collapse
- #backtrace ⇒ Object
- #body ⇒ Object
- #content ⇒ Object
- #has_backtrace? ⇒ Boolean
-
#initialize(object) ⇒ Message
constructor
A new instance of Message.
- #klass ⇒ Object
- #prefix(str) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(object) ⇒ Message
Returns a new instance of Message.
24 25 26 |
# File 'lib/nyanko/logger.rb', line 24 def initialize(object) @object = object end |
Instance Method Details
#backtrace ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/nyanko/logger.rb', line 54 def backtrace if has_backtrace? lines = @object.backtrace[0...Config.backtrace_limit] str = lines.map {|line| " #{line}" }.join("\n") "\n#{str}" end end |
#body ⇒ Object
44 45 46 47 48 |
# File 'lib/nyanko/logger.rb', line 44 def body unless @object..empty? " - #@object" end end |
#content ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/nyanko/logger.rb', line 36 def content if @object.is_a?(Exception) "#{klass}#{body}#{backtrace}" else @object.to_s end end |
#has_backtrace? ⇒ Boolean
62 63 64 |
# File 'lib/nyanko/logger.rb', line 62 def has_backtrace? @object.backtrace end |
#klass ⇒ Object
50 51 52 |
# File 'lib/nyanko/logger.rb', line 50 def klass @object.class end |
#prefix(str) ⇒ Object
32 33 34 |
# File 'lib/nyanko/logger.rb', line 32 def prefix(str) str.split("\n").map {|line| "#{PREFIX} #{line}" }.join("\n") end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/nyanko/logger.rb', line 28 def to_s prefix(content) end |