Class: DataMapper::Logger
- Inherits:
-
Object
- Object
- DataMapper::Logger
- Defined in:
- lib/dm-core/logger.rb
Constant Summary collapse
- 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 developers
DataMapper::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
Returns the value of attribute aio.
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#delimiter ⇒ Object
Returns the value of attribute delimiter.
-
#level ⇒ Object
Returns the value of attribute level.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
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: #<<)
-
#set_log(log, log_level = :off, delimiter = " ~ ", log_creation = false) ⇒ Object
To replace an existing logger with a new one: DataMapper.logger.set_log(logIO,levelString).
Constructor Details
#initialize(*args) ⇒ Logger
To initialize the logger you create a new object, proxies to set_log.
DataMapper::Logger.new(log{String, IO},level{Symbol, String})
145 146 147 |
# File 'lib/dm-core/logger.rb', line 145 def initialize(*args) set_log(*args) end |
Instance Attribute Details
#aio ⇒ Object
Returns the value of attribute aio.
41 42 43 |
# File 'lib/dm-core/logger.rb', line 41 def aio @aio end |
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
44 45 46 |
# File 'lib/dm-core/logger.rb', line 44 def buffer @buffer end |
#delimiter ⇒ Object
Returns the value of attribute delimiter.
42 43 44 |
# File 'lib/dm-core/logger.rb', line 42 def delimiter @delimiter end |
#level ⇒ Object
Returns the value of attribute level.
43 44 45 |
# File 'lib/dm-core/logger.rb', line 43 def level @level end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
45 46 47 |
# File 'lib/dm-core/logger.rb', line 45 def log @log end |
Instance Method Details
#close ⇒ Object
Close and remove the current log object.
DataMapper.logger.close
187 188 189 190 191 |
# File 'lib/dm-core/logger.rb', line 187 def close flush @log.close if @log.respond_to?(:close) @log = nil end |
#flush ⇒ Object
Flush the entire buffer to the log object.
DataMapper.logger.flush
179 180 181 182 |
# File 'lib/dm-core/logger.rb', line 179 def flush return unless @buffer.size > 0 @log.write_method(@buffer.slice!(0..-1).to_s) 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.
204 205 206 |
# File 'lib/dm-core/logger.rb', line 204 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:
DataMapper.logger.set_log(log{String, IO},level{Symbol, String})
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/dm-core/logger.rb', line 157 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) DataMapper.logger = self self.info("Logfile created") if log_creation end |