Class: Ken::Logger
- Inherits:
-
Object
- Object
- Ken::Logger
- Defined in:
- lib/ken/logger.rb
Constant Summary
- LEVELS =
Note:
Ruby (standard) logger levels:
off: absolutely nothing fatal: an unhandleable error that results in a program crash error: a handleable error condition warn: a warning info: generic (useful) information about system operation debug: low-level information for developersKen::Logger::LEVELS[:off, :fatal, :error, :warn, :info, :debug]
{ :off => 99999, :fatal => 7, :error => 6, :warn => 4, :info => 3, :debug => 0 }
Instance Attribute Summary (collapse)
-
- (Object) aio
Returns the value of attribute aio.
-
- (Object) buffer
readonly
Returns the value of attribute buffer.
-
- (Object) delimiter
Returns the value of attribute delimiter.
-
- (Object) level
Returns the value of attribute level.
-
- (Object) log
readonly
Returns the value of attribute log.
Instance Method Summary (collapse)
-
- (Object) close
Close and remove the current log object.
-
- (Object) flush
Flush the entire buffer to the log object.
-
- (Logger) initialize(*args)
constructor
To initialize the logger you create a new object, proxies to set_log.
- - (Object) push(string) (also: #<<)
-
- (Object) set_log(log, log_level = :off, delimiter = " ~ ",, log_creation = false)
To replace an existing logger with a new one:.
Constructor Details
- (Logger) initialize(*args)
To initialize the logger you create a new object, proxies to set_log.
Ken::Logger.new(log{String, IO},level{Symbol, String})
146 147 148 |
# File 'lib/ken/logger.rb', line 146 def initialize(*args) set_log(*args) end |
Instance Attribute Details
- (Object) aio
Returns the value of attribute aio
41 42 43 |
# File 'lib/ken/logger.rb', line 41 def aio @aio end |
- (Object) buffer (readonly)
Returns the value of attribute buffer
44 45 46 |
# File 'lib/ken/logger.rb', line 44 def buffer @buffer end |
- (Object) delimiter
Returns the value of attribute delimiter
42 43 44 |
# File 'lib/ken/logger.rb', line 42 def delimiter @delimiter end |
- (Object) level
Returns the value of attribute level
43 44 45 |
# File 'lib/ken/logger.rb', line 43 def level @level end |
- (Object) log (readonly)
Returns the value of attribute log
45 46 47 |
# File 'lib/ken/logger.rb', line 45 def log @log end |
Instance Method Details
- (Object) close
Close and remove the current log object.
Ken.logger.close
188 189 190 191 192 |
# File 'lib/ken/logger.rb', line 188 def close flush @log.close if @log.respond_to?(:close) @log = nil end |
- (Object) flush
Flush the entire buffer to the log object.
Ken.logger.flush
180 181 182 183 |
# File 'lib/ken/logger.rb', line 180 def flush return unless @buffer.size > 0 @log.write_method(@buffer.slice!(0..-1).join) end |
- (Object) push(string) Also known as: <<
Note that the string is discarded if the string's log level less than the logger's log level.
Note that if the logger is aio capable then the logger will use non-blocking asynchronous writes.
205 206 207 |
# File 'lib/ken/logger.rb', line 205 def push(string) internal_push(string) end |
- (Object) set_log(log, log_level = :off, delimiter = " ~ ",, log_creation = false)
To replace an existing logger with a new one:
Ken.logger.set_log(log{String, IO},level{Symbol, String})
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/ken/logger.rb', line 158 def set_log(log, log_level = :off, delimiter = " ~ ", log_creation = false) delimiter ||= " ~ " if log_level && LEVELS[log_level.to_sym] self.level = log_level.to_sym else self.level = :debug end @buffer = [] @delimiter = delimiter initialize_log(log) Ken.logger = self self.info("Logfile created") if log_creation end |