Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logs don't rotate when using RollingFileAppender #524

Open
LinArcX opened this issue Aug 21, 2021 · 5 comments
Open

Logs don't rotate when using RollingFileAppender #524

LinArcX opened this issue Aug 21, 2021 · 5 comments
Assignees
Labels

Comments

@LinArcX
Copy link

LinArcX commented Aug 21, 2021

This is my log4cplus.properties file:

# Root logger option
log4cplus.rootLogger=DEBUG, stdout

# Console
log4cplus.appender.stdout=log4cplus::ConsoleAppender
log4cplus.appender.stdout.layout=log4cplus::PatternLayout
log4cplus.appender.stdout.layout.ConversionPattern=%d{%Y/%m/%d %H:%M:%S}-[%-5p][%c{1}][%t] - %m -[%l]%n

# TEST
log4cplus.logger.test=DEBUG, test
log4cplus.appender.test=log4cplus::RollingFileAppender
log4cplus.appender.test.CreateDirs=true
log4cplus.appender.test.MaxFileSize=3KB
log4cplus.appender.test.MaxBackupIndex=1
log4cplus.appender.test.DatePattern=%Y_%m_%d.%H_%M_%S
log4cplus.appender.test.layout=log4cplus::PatternLayout
log4cplus.appender.test.filePattern=%i.log.zip
log4cplus.appender.test.File=C:\\Program Files\\test\\logs\\test.log
log4cplus.appender.test.layout.ConversionPattern=%D{%Y/%m/%d %H:%M:%S} - [%-5p][%-3t][%c{1}] - %m - [%l]%n

And this is my simple application to test rotating feature:

#include <log4cplus/logger.h>
#include <log4cplus/loggingmacros.h>
#include <log4cplus/configurator.h>
	
int
main()
{
    log4cplus::initialize();
    log4cplus::Logger root = log4cplus::Logger::getRoot();

    log4cplus::BasicConfigurator config;
    config.configure();
    log4cplus::PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT ("C:\\Program Files\\test\\log4cplus.properties"));

    log4cplus::Logger testLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("test"));

    LOG4CPLUS_DEBUG(testLogger , LOG4CPLUS_TEXT("FOO."));
    LOG4CPLUS_INFO(testLogger , LOG4CPLUS_TEXT("BAR."));

    log4cplus::Logger::shutdown();
    return 0;
}

I run the application many times to reach 3KB, but it doesn't rotate file(i don't see any .zip file in log directory).

@wilx wilx self-assigned this Aug 21, 2021
@wilx
Copy link
Contributor

wilx commented Aug 21, 2021

There is a minimum file size that you cannot go below. It is 200 KiB.

@LinArcX
Copy link
Author

LinArcX commented Aug 21, 2021

Oh, interesting..

It works but the rotated file name is: test.log.1

I expected it to be zipped and it's name should be like this:
test.log.2021_08_21.10_14_15.zip

@wilx
Copy link
Contributor

wilx commented Aug 21, 2021

RollingFileAppender is only for rolling by size. If you want time based rolling, you would use TimeBasedRollingFileAppender. But TimeBasedRollingFileAppender does not roll by size.

@wilx wilx added the question label Aug 21, 2021
@LinArcX
Copy link
Author

LinArcX commented Aug 21, 2021

No i don't want time based rolling. I just wanted to have a zipped file.(something like: test.log.zip is enough for now: )

@LinArcX
Copy link
Author

LinArcX commented Aug 21, 2021

Look at this thread response:
https://stackoverflow.com/a/51865893

Seems log4cplus doesn't have rollingPolicy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants