Class: DataObjects::Logger
- Inherits:
-
Object
- Object
- DataObjects::Logger
- Defined in:
- lib/data_objects/logger.rb
Overview
Public DataObjects Logger API
Logger taken from Merb :)
To replace an existing logger with a new one:
DataObjects::Logger.set_log(log{String, IO},level{Symbol, String})
Available logging levels are
DataObjects::Logger::{ Fatal, Error, Warn, Info, Debug }
Logging via:
DataObjects.logger.fatal(message<String>)
DataObjects.logger.error(message<String>)
DataObjects.logger.warn(message<String>)
DataObjects.logger.info(message<String>)
DataObjects.logger.debug(message<String>)
Flush the buffer to
DataObjects.logger.flush
Remove the current log object
DataObjects.logger.close
Private DataObjects Logger API
To initialize the logger you create a new object, proxies to set_log.
DataObjects::Logger.new(log{String, IO},level{Symbol, String})
Logger will not create the file until something is actually logged This avoids file creation on DataObjects init when it creates the default logger.
Defined Under Namespace
Classes: Message
Constant Summary collapse
- LEVELS =
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 developers
DataObjects::Logger::LEVELS[:off, :fatal, :error, :warn, :info, :debug]
{ :off => 99999, :fatal => 7, :error => 6, :warn => 4, :info => 3, :debug => 0 }
Instance Attribute Summary collapse
-
#aio ⇒ Object
Use asynchronous I/O?.
-
#buffer ⇒ Object
readonly
Direct access to the buffer.
-
#delimiter ⇒ Object
delimiter to use between message sections.
-
#level ⇒ Object
a symbol representing the log level from :fatal, :error, :warn, :info, :debug.
-
#log ⇒ Object
readonly
The name of the log file.
Instance Method Summary collapse
-
#close ⇒ Object
Close and remove the current log object.
-
#flush ⇒ Object
Flush the entire buffer to the log object.
-
#initialize(*args) ⇒ Logger
constructor
To initialize the logger you create a new object, proxies to set_log.
-
#push(string) ⇒ Object
(also: #<<)
Note that the string is discarded if the string’s log level less than the logger’s log level.
-
#set_log(log, log_level = :off, delimiter = " ~ ", log_creation = false) ⇒ Object
To replace an existing logger with a new one: DataObjects::Logger.set_log(logIO,levelString).
Constructor Details
#initialize(*args) ⇒ Logger
To initialize the logger you create a new object, proxies to set_log.
DataObjects::Logger.new(log{String, IO},level{Symbol, String})
167 168 169 |
# File 'lib/data_objects/logger.rb', line 167 def initialize(*args) set_log(*args) end |
Instance Attribute Details
#aio ⇒ Object
Use asynchronous I/O?
56 57 58 |
# File 'lib/data_objects/logger.rb', line 56 def aio @aio end |
#buffer ⇒ Object (readonly)
Direct access to the buffer
62 63 64 |
# File 'lib/data_objects/logger.rb', line 62 def buffer @buffer end |
#delimiter ⇒ Object
delimiter to use between message sections
58 59 60 |
# File 'lib/data_objects/logger.rb', line 58 def delimiter @delimiter end |
#level ⇒ Object
a symbol representing the log level from :fatal, :error, :warn, :info, :debug
60 61 62 |
# File 'lib/data_objects/logger.rb', line 60 def level @level end |
#log ⇒ Object (readonly)
The name of the log file
64 65 66 |
# File 'lib/data_objects/logger.rb', line 64 def log @log end |
Instance Method Details
#close ⇒ Object
Close and remove the current log object.
DataObjects.logger.close
210 211 212 213 214 |
# File 'lib/data_objects/logger.rb', line 210 def close flush @log.close if @log.respond_to?(:close) @log = nil end |
#flush ⇒ Object
Flush the entire buffer to the log object.
DataObjects.logger.flush
202 203 204 205 |
# File 'lib/data_objects/logger.rb', line 202 def flush return unless @buffer.size > 0 @log.write_method(@buffer.slice!(0..-1).join) end |
#push(string) ⇒ Object 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.
227 228 229 |
# File 'lib/data_objects/logger.rb', line 227 def push(string) internal_push(string) end |
#set_log(log, log_level = :off, delimiter = " ~ ", log_creation = false) ⇒ Object
To replace an existing logger with a new one:
DataObjects::Logger.set_log(log{String, IO},level{Symbol, String})
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/data_objects/logger.rb', line 180 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) DataObjects.logger = self self.info("Logfile created") if log_creation end |