Class: LogKernel::Logger

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

Constant Summary

Constants included from Level

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



128
129
130
131
132
133
134
135
# File 'lib/logutils/logger.rb', line 128

def initialize
  @handlers = []
  @handlers << STDHANDLER   # by default log to console

  ## todo/check: pass levelno through to handlers?
  #   do we need a "global" levelno in the logger?
  @levelno = ALL
end

Instance Attribute Details

#handlersObject (readonly)

Returns the value of attribute handlers.



137
138
139
# File 'lib/logutils/logger.rb', line 137

def handlers
  @handlers
end

Class Method Details

.[](class_or_name) ⇒ Object



120
121
122
# File 'lib/logutils/logger.rb', line 120

def self.[]( class_or_name )
  STDLOGGER
end

.rootObject



124
125
126
# File 'lib/logutils/logger.rb', line 124

def self.root
  STDLOGGER
end

Instance Method Details

#debug(msg) ⇒ Object



150
151
152
# File 'lib/logutils/logger.rb', line 150

def debug( msg )
  write( Event.new( DEBUG, msg ) )
end

#error(msg) ⇒ Object



162
163
164
# File 'lib/logutils/logger.rb', line 162

def error( msg )
  write( Event.new( ERROR, msg ) )
end

#fatal(msg) ⇒ Object



166
167
168
# File 'lib/logutils/logger.rb', line 166

def fatal( msg )
  write( Event.new( FATAL, msg ) )
end

#info(msg) ⇒ Object



154
155
156
# File 'lib/logutils/logger.rb', line 154

def info( msg )
  write( Event.new( INFO, msg ) )
end

#level=(key) ⇒ Object

NB: use :debug, :info, :warn, :error, etc as argument

if invalid argument gets passed in, level gets set to UNKNOWN


145
146
147
# File 'lib/logutils/logger.rb', line 145

def level=( key )
  @levelno = LEVEL_HASH.fetch( key, UNKNOWN )
end

#unknown(msg) ⇒ Object



170
171
172
# File 'lib/logutils/logger.rb', line 170

def unknown( msg )
  write( Event.new( UNKNOWN, msg ) )
end

#warn(msg) ⇒ Object



158
159
160
# File 'lib/logutils/logger.rb', line 158

def warn( msg )
  write( Event.new( WARN, msg ) )
end