mschilli / log4perl

Log4j Implementation For Perl
http://log4perl.com
Other
116 stars 66 forks source link

Appender::Screen buffering issue when used inside Docker container #115

Closed abraxxa closed 2 years ago

abraxxa commented 2 years ago

While containerizing my Catalyst applications, which use Log::Log4perl::Catalyst and ::Appender::Screen, I've faced the issue of massively delayed log messages. After trying multiple solutions (non-blocking docker logging, Log::Log4perl::Catalyst->new(..., { autoflush => 1 });) I came across https://perldoc.perl.org/perlfaq5#How-do-I-flush%2Funbuffer-an-output-filehandle%3F-Why-must-I-do-this%3F.

Adding

STDOUT->autoflush(1);
STDERR->autoflush(1);

to each Catalyst apps main package fixed the issue but isn't nice as it isn't part of the log config but the code.

I'm proposing a new ::Appender::Screen config option autoflush which enables autoflush for the configured output STDOUT or STDERR, depending on the existing stderr config option.

If you agree I'm willing to write a pull-request for it.