Class: Piper::LogRec

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#kindObject (readonly)

Returns the value of attribute kind.



26
27
28
# File 'lib/piper/logrec.rb', line 26

def kind
  @kind
end

#tidObject

Returns the value of attribute tid.



31
32
33
# File 'lib/piper/logrec.rb', line 31

def tid
  @tid
end

#whatObject

Returns the value of attribute what.



30
31
32
# File 'lib/piper/logrec.rb', line 30

def what
  @what
end

#whenObject

Returns the value of attribute when.



27
28
29
# File 'lib/piper/logrec.rb', line 27

def when
  @when
end

#whereObject

Returns the value of attribute where.



29
30
31
# File 'lib/piper/logrec.rb', line 29

def where
  @where
end

#whoObject

Returns the value of attribute who.



28
29
30
# File 'lib/piper/logrec.rb', line 28

def who
  @who
end

Class Method Details

.whoObject



23
24
25
# File 'lib/piper/logrec.rb', line 23

def self.who()
  return @@who
end

Instance Method Details

#to_sObject



53
54
55
# File 'lib/piper/logrec.rb', line 53

def to_s()
  Oj.dump(self, :mode => :compat, :time_format => :unix)
end