Module: Logging::Appenders::Buffering

Included in:
Email, IO
Defined in:
lib/logging/appenders/buffering.rb

Overview

The Buffering module is used to implement buffering of the log messages in a given appender. The size of the buffer can be specified, and the buffer can be configured to auto-flush at a given threshold. The threshold can be a single message or a very large number of messages.

Log messages of a certain level can cause the buffer to be flushed immediately. If an error occurs, all previous messages and the error message will be written immediately to the logging destination if the buffer is configured to do so.

Constant Summary collapse

DEFAULT_BUFFER_SIZE =

Default buffer size

500

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#auto_flushingObject

The auto-flushing setting. When the buffer reaches this size, all messages will be be flushed automatically.



27
28
29
# File 'lib/logging/appenders/buffering.rb', line 27

def auto_flushing
  @auto_flushing
end

#bufferObject (readonly)

The buffer holding the log messages



22
23
24
# File 'lib/logging/appenders/buffering.rb', line 22

def buffer
  @buffer
end

Instance Method Details

#flushObject

This message must be implemented by the including class. The method should write the contents of the buffer to the logging destination, and it should clear the buffer when done.

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/logging/appenders/buffering.rb', line 33

def flush
  raise NotImplementedError
end

#immediate_at=(level) ⇒ Object

Configure the levels that will trigger and immediate flush of the logging buffer. When a log event of the given level is seen, the buffer will be flushed immediately. Only the levels explicitly given in this assignment will flush the buffer; if an “error” message is configured to immediately flush the buffer, a “fatal” message will not even though it is a higher level. Both must be explicitly passed to this assignment.

You can pass in a single leveal name or number, and array of level names or numbers, or a string containg a comma separated list of level names or numbers.

immediate_at = :error
immediate_at = [:error, :fatal]
immediate_at = "warn, error"


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/logging/appenders/buffering.rb', line 53

def immediate_at=( level )
  @immediate ||= []
  @immediate.clear

  # get the immediate levels -- no buffering occurs at these levels, and
  # a log message is written to the logging destination immediately
  immediate_at =
    case level
    when String; level.split(',').map {|x| x.strip}
    when Array; level
    else Array(level) end
  
  immediate_at.each do |lvl|
    num = ::Logging.level_num(lvl)
    next if num.nil?
    @immediate[num] = true
  end
end