-
Notifications
You must be signed in to change notification settings - Fork 566
Description
Hi,
I am using 1.2.1 of log4cplus and have an issue with the TimeBasedRollingFileAppender. I am limited to Visual Studio 2010, so can't use C++11 but have tried version 2.0.3 on a different machine with the same results.
I find that the TimeBasedRollingFileAppender does not clean up the correct log files when MaxHistory is set. I am not sure if I am misunderstanding how it is supposed to work or if there is an issue in my setup.
The sample below recreates the issue for me.
#include "log4cplus/logger.h"
#include "log4cplus/loggingmacros.h"
#include "log4cplus/configurator.h"
#include "log4cplus/fileappender.h"
int _tmain(int argc, _TCHAR* argv[])
{
::log4cplus::initialize();
::log4cplus::PropertyConfigurator::doConfigure("config.ini");
log4cplus::Logger logger(log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("Test")));
LOG4CPLUS_DEBUG(logger, "TestOutput");
return 0;
}
My config.ini file contains the following.
log4cplus.logger.Test=DEBUG, TestLogAppender
#TestLogAppender Configuration
log4cplus.appender.TestLogAppender = log4cplus::TimeBasedRollingFileAppender
log4cplus.appender.TestLogAppender.FilenamePattern = %d{yyyyMMdd}.log
log4cplus.appender.TestLogAppender.MaxHistory = 2
log4cplus.appender.TestLogAppender.CleanHistoryOnStart = true
log4cplus.appender.TestLogAppender.Schedule = DAILY
log4cplus.appender.TestLogAppender.RollOnClose = false
log4cplus.appender.TestLogAppender.layout = log4cplus::PatternLayout
log4cplus.appender.TestLogAppender.layout.ConversionPattern = %D{%Y-%m-%d %H:%M:%S.%q} [%-5p] %m%n
When I run this, I find that it clears out all old logfiles, rather than only those that are more than 2 days old.
I am able to correct this by modifying the init
method on the TimeBasedRollingFileAppender so instead of calling clean(now + maxHistory*getRolloverPeriodDuration())
it just calls clean(now)
. I don't know if this is actually the issue or if I have something set up incorrectly.
Additional information:
- version: 1.2.1 and 2.0.3
- operating system, CPU, bitness: Windows 7 and Windows 10, Intel, 64 bit
configure
script, or CMake, etc., flags and settings: defaults, using VS project files provided.- flags and settings used by your application: Visual Studio defaults
- compiler and its version: Visual Studio 2010, v100 or Visual Studio 2017, v141.
Thanks