Module | Logging::Appenders::Buffering |
In: |
lib/logging/appenders/buffering.rb
|
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.
DEFAULT_BUFFER_SIZE | = | 500; | Default buffer size |
auto_flushing | [R] | The auto-flushing setting. When the buffer reaches this size, all messages will be be flushed automatically. |
buffer | [R] | The buffer holding the log messages |
flush_period | [R] | When set, the buffer will be flushed at regular intervals defined by the flush_period. |
Setup the message buffer and other variables for automatically and periodically flushing the buffer.
Configure the auto-flushing threshold. Auto-flushing is used to flush the contents of the logging buffer to the logging destination automatically when the buffer reaches a certain threshold.
By default, the auto-flushing will be configured to flush after each log message.
The allowed settings are as follows:
N : flush after every N messages (N is an integer) true : flush after each log message false OR nil OR 0 : only flush when the buffer is full (500 messages)
If the default buffer size of 500 is too small, then you can manually configure it to be as large as you want. This will consume more memory.
auto_flushing = 42_000
Close the message buffer by flushing all log events to the appender. If a periodic flusher thread is running, shut it down and allow it to exit.
Call flush to force an appender to write out any buffered log events. Similar to IO#flush, so use in a similar fashion.
Configure periodic flushing of the message buffer. Periodic flushing is used to flush the contents of the logging buffer at some regular interval. Periodic flushing is disabled by default.
When enabling periodic flushing the flush period should be set using one of the following formats: "HH:MM:SS" or seconds as an numeric or string.
"01:00:00" : every hour "00:05:00" : every 5 minutes "00:00:30" : every 30 seconds 60 : every 60 seconds (1 minute) "120" : every 120 seconds (2 minutes)
For the periodic flusher to work properly, the auto-flushing threshold will be set to the default value of 500. The auto-flushing threshold can be changed, but it must be greater than 1.
To disable the periodic flusher simply set the flush period to nil. The auto-flushing threshold will not be changed; it must be disabled manually if so desired.
Configure the levels that will trigger an 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 level name or number, an array of level names or numbers, or a string containing a comma separated list of level names or numbers.
immediate_at = :error immediate_at = [:error, :fatal] immediate_at = "warn, error"
Reopen the connection to the underlying logging destination. In addition if the appender is configured for periodic flushing, then the flushing thread will be stopped and restarted.
Configure the buffering using the arguments found in the give options hash. This method must be called in order to use the message buffer. The supported options are "immediate_at" and "auto_flushing". Please refer to the documentation for those methods to see the allowed options.