mirror of
https://github.com/meineerde/rackstash.git
synced 2026-02-01 01:37:12 +00:00
Extract Buffer#auto_flush method
This method is responsible to automatically flish non-buffering Buffers when there are messages added
This commit is contained in:
parent
cca00408e2
commit
4baa1b97f6
@ -125,20 +125,17 @@ module Rackstash
|
||||
# added message if it wasn't set earlier already.
|
||||
#
|
||||
# If the buffer is not {#buffering?}, it will be {#flush}ed and {#clear}ed
|
||||
# after each added message. All fields and tags added before the log message
|
||||
# will be flushed along with the single message.
|
||||
# after each added message. All fields, tags, and messages added before as
|
||||
# well as the message added with this method call will be flushed.
|
||||
#
|
||||
# @param message [Message] A {Message} to add to the current message
|
||||
# buffer.
|
||||
# @return [Message] the passed `message`
|
||||
def add_message(message)
|
||||
@messages << message
|
||||
timestamp(message.time)
|
||||
@messages << message
|
||||
|
||||
unless buffering?
|
||||
flush
|
||||
clear
|
||||
end
|
||||
auto_flush
|
||||
|
||||
message
|
||||
end
|
||||
@ -314,5 +311,22 @@ module Rackstash
|
||||
|
||||
event
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Non buffering buffers, i.e., those with `buffering: false`, flush
|
||||
# themselves to the sink whenever there is something logged to it. That way,
|
||||
# such a buffer acts like a regular old Logger would: it just flushes a
|
||||
# logged message to its log device as soon as it is logged.
|
||||
#
|
||||
# By calling `auto_flush`, the current buffer is flushed and cleared
|
||||
|
||||
# Flush and clear the current buffer if necessary.
|
||||
def auto_flush
|
||||
return if buffering?
|
||||
|
||||
flush
|
||||
clear
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user