I have log4j configured to rotate the log every day.
In special situations I would like to trigger an additional log rotation manually.
Is this possible - an
For log4j2, you can use following.
org.apache.logging.log4j.Logger logManagerLogger = LogManager.getLogger();
Map appenders = ((org.apache.logging.log4j.core.Logger) logManagerLogger).getAppenders();
appenders.forEach((appenderName, appender) -> {
if (appender instanceof RollingFileAppender) {
logger.info("Rolling over appender " + appenderName);
((RollingFileAppender) appender).getManager().rollover();
}
});