| Class | ActiveSupport::BufferedLogger |
| In: |
activesupport/lib/active_support/buffered_logger.rb
|
| Parent: | Object |
| auto_flushing | [RW] | |
| buffer | [R] | |
| level | [RW] |
# File activesupport/lib/active_support/buffered_logger.rb, line 35 def initialize(log, level = DEBUG) @level = level @buffer = "" @auto_flushing = true if log.respond_to?(:write) @log = log elsif File.exist?(log) @log = open(log, (File::WRONLY | File::APPEND)) @log.sync = true else @log = open(log, (File::WRONLY | File::APPEND | File::CREAT)) @log.sync = true @log.write("# Logfile created on %s" % [Time.now.to_s]) end end
# File activesupport/lib/active_support/buffered_logger.rb, line 52 def add(severity, message = nil, progname = nil, &block) return if @level > severity message = (message || (block && block.call) || progname).to_s # If a newline is necessary then create a new message ending with a newline. # Ensures that the original message is not mutated. message = "#{message}\n" unless message[-1] == ?\n @buffer << message flush if auto_flushing message end
# File activesupport/lib/active_support/buffered_logger.rb, line 81 def close flush @log.close if @log.respond_to?(:close) @log = nil end
# File activesupport/lib/active_support/buffered_logger.rb, line 76 def flush return if @buffer.size == 0 @log.write(@buffer.slice!(0..-1)) end
Silences the logger for the duration of the block.
# File activesupport/lib/active_support/buffered_logger.rb, line 19 def silence(temporary_level = ERROR) if silencer begin old_logger_level, self.level = level, temporary_level yield self ensure self.level = old_logger_level end else yield self end end