Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0fd8ca8

Browse filesBrowse files
authored
Merge pull request #19 from yoheimuta/call-buffer_overflow_handler-at-close
Called the buffer_overflow_handler at close()
2 parents 707125a + 0473380 commit 0fd8ca8
Copy full SHA for 0fd8ca8

File tree

Expand file treeCollapse file tree

2 files changed

+5
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+5
-2
lines changed

‎lib/Fluent/Logger.pm

Copy file name to clipboardExpand all lines: lib/Fluent/Logger.pm
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ sub close {
140140
if ($@ || !$written) {
141141
my $size = length $self->{pending};
142142
$self->_carp("Can't send pending data. LOST $size bytes.: $@");
143+
$self->_call_buffer_overflow_handler();
143144
}
144145
else {
145146
$self->_carp("pending data was flushed successfully");
@@ -341,6 +342,7 @@ You can inject your own custom coderef to handle buffer overflow in the event of
341342
This will mitigate the loss of data instead of simply throwing data away.
342343
343344
Your proc should accept a single argument, which will be the internal buffer of messages from the logger.
345+
This coderef is also called when logger.close() failed to flush the remaining internal buffer of messages.
344346
A typical use-case for this would be writing to disk or possibly writing to Redis.
345347
346348
=item truncate_buffer_at_overflow

‎t/09_buffer_overflow_handler.t

Copy file name to clipboardExpand all lines: t/09_buffer_overflow_handler.t
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ my $no_such_logger = Fluent::Logger->new(
1818
for (1..10) {
1919
$no_such_logger->post("test", { "k" => "v" x (1024 * 1024) });
2020
}
21-
undef $no_such_logger;
21+
is $handler_called, 1, 'called once at buffer_overflow';
2222

23-
is $handler_called, 1;
23+
undef $no_such_logger;
24+
is $handler_called, 2, 'called once at close';
2425

2526
done_testing;
2627

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.