Class: Piper::LogRec
- Inherits:
-
Object
- Object
- Piper::LogRec
- Defined in:
- lib/piper/logrec.rb
Overview
Piper::LogRec is a class for creating JSON log records for Piper Push Cache server.
Constant Summary collapse
- @@level_map =
{ 'fatal' => 0, 'error' => 1, 'warn' => 2, 'info' => 3, 'debug' => 4, :fatal => 0, :error => 1, :warn => 2, :info => 3, :debug => 4, }
- @@who =
File.basename($PROGRAM_NAME)
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#tid ⇒ Object
Returns the value of attribute tid.
-
#what ⇒ Object
Returns the value of attribute what.
-
#when ⇒ Object
Returns the value of attribute when.
-
#where ⇒ Object
Returns the value of attribute where.
-
#who ⇒ Object
Returns the value of attribute who.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(level, what, tid = nil, where = nil) ⇒ LogRec
constructor
A new instance of LogRec.
- #to_s ⇒ Object
Constructor Details
#initialize(level, what, tid = nil, where = nil) ⇒ LogRec
Returns a new instance of LogRec.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/piper/logrec.rb', line 33 def initialize(level, what, tid=nil, where=nil) @kind = 'Log' if level.is_a?(Integer) @level = level else @level = @@level_map[level] end @who = @@who if where.nil? loc = caller_locations(2,1)[0] @where = "#{File.basename(loc.path)}:#{loc.lineno}" else @where = where end @what = what @when = Time.now @when.gmtime unless @when.gmt? @tid = tid end |
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
26 27 28 |
# File 'lib/piper/logrec.rb', line 26 def kind @kind end |
#tid ⇒ Object
Returns the value of attribute tid.
31 32 33 |
# File 'lib/piper/logrec.rb', line 31 def tid @tid end |
#what ⇒ Object
Returns the value of attribute what.
30 31 32 |
# File 'lib/piper/logrec.rb', line 30 def what @what end |
#when ⇒ Object
Returns the value of attribute when.
27 28 29 |
# File 'lib/piper/logrec.rb', line 27 def when @when end |
#where ⇒ Object
Returns the value of attribute where.
29 30 31 |
# File 'lib/piper/logrec.rb', line 29 def where @where end |
#who ⇒ Object
Returns the value of attribute who.
28 29 30 |
# File 'lib/piper/logrec.rb', line 28 def who @who end |
Class Method Details
.who ⇒ Object
23 24 25 |
# File 'lib/piper/logrec.rb', line 23 def self.who() return @@who end |
Instance Method Details
#to_s ⇒ Object
53 54 55 |
# File 'lib/piper/logrec.rb', line 53 def to_s() Oj.dump(self, :mode => :compat, :time_format => :unix) end |