Class: LogUtils::Kernel::Event

Inherits:
Object
  • Object
show all
Includes:
Level
Defined in:
lib/logutils/logger.rb

Constant Summary collapse

LEVEL_NAME =
[
 'all',    # 0
 'debug',  # 1
 'info',   # 2
 'warn',   # 3
 'error',  # 4
 'fatal',  # 5
 'off'     # 6
]

Constants included from Level

Level::ALL, Level::DEBUG, Level::ERROR, Level::FATAL, Level::INFO, Level::OFF, Level::WARN

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(levelno, msg) ⇒ Event

Returns a new instance of Event.



42
43
44
45
46
47
48
49
50
# File 'lib/logutils/logger.rb', line 42

def initialize( levelno, msg )
  @levelno = levelno    # pass in integer e.g. 0,1,2,3,etc.
  @msg     = msg
  
  @pid   = Process.pid
  @tid   = Thread.current.object_id
  
  @ts    = Time.now
end

Instance Attribute Details

#msgObject (readonly)

Returns the value of attribute msg.



56
57
58
# File 'lib/logutils/logger.rb', line 56

def msg
  @msg
end

#pidObject (readonly)

process_id



57
58
59
# File 'lib/logutils/logger.rb', line 57

def pid
  @pid
end

#tidObject (readonly)

thread_id



58
59
60
# File 'lib/logutils/logger.rb', line 58

def tid
  @tid
end

#tsObject (readonly)

timestamp



59
60
61
# File 'lib/logutils/logger.rb', line 59

def ts
  @ts
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/logutils/logger.rb', line 66

def error?
  @levelno == ERROR
end

#fatal?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/logutils/logger.rb', line 62

def fatal?
  @levelno == FATAL
end

#levelObject



52
53
54
# File 'lib/logutils/logger.rb', line 52

def level
  LEVEL_NAME[ @levelno ]
end

#to_sObject



75
76
77
78
# File 'lib/logutils/logger.rb', line 75

def to_s
  # "[#{level}-#{pid}.#{tid}] #{msg}"
  "[#{level}] #{msg}"
end

#warn?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/logutils/logger.rb', line 70

def warn?
  @levelno == WARN
end