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 developersDataObjects::Logger::LEVELS[:off, :fatal, :error, :warn, :info, :debug]
{ off: 99_999, fatal: 7, error: 6, warn: 4, info: 3, debug: 0 }.freeze
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})
159 160 161 |
# File 'lib/data_objects/logger.rb', line 159 public def initialize(*args) set_log(*args) end |
Instance Attribute Details
#aio ⇒ Object
Use asynchronous I/O?
52 53 54 |
# File 'lib/data_objects/logger.rb', line 52 def aio @aio end |
#buffer ⇒ Object (readonly)
Direct access to the buffer
58 59 60 |
# File 'lib/data_objects/logger.rb', line 58 def buffer @buffer end |
#delimiter ⇒ Object
delimiter to use between message sections
54 55 56 |
# File 'lib/data_objects/logger.rb', line 54 def delimiter @delimiter end |
#level ⇒ Object
a symbol representing the log level from :fatal, :error, :warn, :info, :debug
56 57 58 |
# File 'lib/data_objects/logger.rb', line 56 def level @level end |
#log ⇒ Object (readonly)
The name of the log file
60 61 62 |
# File 'lib/data_objects/logger.rb', line 60 def log @log end |
Instance Method Details
#close ⇒ Object
Close and remove the current log object.
DataObjects.logger.close
203 204 205 206 207 |
# File 'lib/data_objects/logger.rb', line 203 public 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
194 195 196 197 198 |
# File 'lib/data_objects/logger.rb', line 194 public def flush return unless @buffer.size.positive? @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.
Is this old or does the method receive mixed params? level<Fixnum> the logging level as an integer
220 221 222 |
# File 'lib/data_objects/logger.rb', line 220 public 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})
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/data_objects/logger.rb', line 172 public def set_log(log, log_level = :off, delimiter = ' ~ ', log_creation = false) delimiter ||= ' ~ ' self.level = if log_level && LEVELS[log_level.to_sym] log_level.to_sym else :debug end @buffer = [] @delimiter = delimiter initialize_log(log) DataObjects.logger = self info('Logfile created') if log_creation end |