mschilli / log4perl

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

[Bug] Log::Log4perl::Appender::File::file_switch() ignores the create_at_logtime option #111

Open XSven opened 2 years ago

XSven commented 2 years ago

Log-Log4perl-1.54

Switching the log file name using the file_switch() method, creates a new logfile even if the create_at_logtime option is set to true. Maybe the line 271 in Log::Log4perl::Appender::File should be changed from

$self->file_open();

to

$self->file_open() unless $self->{create_at_logtime};

mohawk2 commented 2 years ago

Can you capture this in a bit of test code?

XSven commented 1 year ago

These 2 ok() test assertions should pass. Unfortunately the second one is failing.

#########################################################
# Testing create_at_logtime with file_switch()
#########################################################
unlink "${testfile}_6"; # delete leftovers from previous tests

$data = qq(
log4perl.category                  = DEBUG, Logfile
log4perl.appender.Logfile          = Log::Log4perl::Appender::File
log4perl.appender.Logfile.filename = ${testfile}_6
log4perl.appender.Logfile.create_at_logtime = 1
log4perl.appender.Logfile.layout   = Log::Log4perl::Layout::SimpleLayout
);

Log::Log4perl->init(\$data);
ok(! -f "${testfile}_6");

$app = Log::Log4perl->appenders()->{Logfile};
$app->file_switch("${testfile}_7");
ok(! -f "${testfile}_7");

unlink "${testfile}_6", "${testfile}_7";