how to roll a new log file in routing appender everyday - java

My routing log4j2.xml should role log file based on user login.
Assume a user logs in the application for consecutive 3 days and do his stuff for around half an hour and then logs out. So as per requirement 3 log files should be created for the logged user (one file per day basis in separate file)
like e.g.
john-20-11-2015.log,
john-21-11-2015.log,
john-22-11-2015.log
below is the Log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<Configuration status="WARN" name="MySite" monitorInterval="30">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout>
<pattern>[%-5level] [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%c{1}] - %msg%n</pattern>
</PatternLayout>
</Console>
<RollingFile name="error-log"
fileName="D:/myLogs/error [${date:yyyy-MM-dd}].log" filePattern="D:/myLogs/error-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%c{1}] - %msg%n</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
</RollingFile>
<RollingFile name="trace-log"
fileName="D:/myLogs/trace [${date:yyyy-MM-dd}].log" filePattern="D:/myLogs/trace-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%c{1}] - %msg%n</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
</RollingFile>
<Routing name="RoutingAppender">
<Routes pattern="$${ctx:logFileName}">
<Route>
<RollingFile name="Rolling-${ctx:logFileName}" append="true"
fileName="D:/myLogs/${ctx:logFileName}~${date:yyyy-MM-dd}.log"
filePattern="D:/myLogs/%d{yyyy-MM-dd}-%i.log">
<PatternLayout
pattern="SERVER-LOG: [%-5level] [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%logger{1}] - %msg%n" />
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
</RollingFile>
</Route>
<Route ref="Console" key="$${ctx:logFileName}" />
</Routes>
</Routing>
</Appenders>
<Loggers>
<Root level="trace" additivity="false">
<Appender-Ref ref="Console"/>
<appender-ref ref="error-log" level="error"/>
<appender-ref ref="trace-log" level="trace"/>
<Appender-Ref ref="RoutingAppender" />
</Root>
</Loggers>
</Configuration>
I am calling
ThreadContext.put("logFileName", userName);
to append the log in the routing appender, the log were appending correctly in the respective logs
and I am clearing the threadcontext during logout method
ThreadContext.remove("logFileName");
ThreadContext.clearAll();
I hosted my application in tomcat. log files were generated based on logged user for every user based on the file name pattern, but log is not generated on daily basis, instead of that its appended the current day log of users in previous day log
eg: john-20-11-2015.log contains the log of of 21st and 22nd
its roles a new log file only when tomcat is stop started .
guys help me out.. is there anything wrong

I think you want DailyRollingFileAppender here is an example
Also please look at the similar question
example:
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
...
<param name="DatePattern" value="'.'yyyy-MM-dd" />
...
</appender>

The filename attribute is only evaluated when the appender is created. It does not change on each rollover. You should get a new file on each rollover that does have the correct date in it.
Is that not what you are seeing?

Related

Log4j does not print to console nor write to file

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class AzulMain {
private static final Logger LOGGER = LogManager.getLogger(AzulMain.class.getName());
public static void main(String[] args){
LOGGER.info("Maybe my first Logger works?");
}
}
The imports work fine. I use these jar-files:
log4j-1.2-api-2.17.2.jar
log4j-api.2.17.2.jar
log4j-core-2.17.2.jar
And this is how my XML-file (log4j2.xml) looks. It is in the same folder as my AzulMain:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
<Properties>
<Property name="log-path">log/${date:yyyy-MM-dd HH-mm-ss-SSS}</Property>
<Property name="archive">${log-path}/archive</Property>
</Properties>
<Appenders>
<Console name="Console-Appender" target="SYSTEM_OUT">
<PatternLayout>
<pattern>
%d{HH:mm:ss.SSS} %-5level %class{36} %L %M - %msg%xEx%n
</pattern>
</PatternLayout>
</Console>
<File name="File-Appender-AzulMain" fileName="${log-path}/Azul.log">
<PatternLayout>
<pattern>
%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %class{36} %L %M - %msg%xEx%n
</pattern>
</PatternLayout>
</File>
<RollingFile name="RollingFile-Appender"
fileName="${log-path}/rollingfile.log"
filePattern="${archive}/rollingfile.log.%d{yyyy-MM-dd#HH-mm}.gz">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %class{36} %L %M - %msg%xEx%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="30 MB"/>
</Policies>
<DefaultRolloverStrategy max="30"/>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="AzulMain" level="trace" additivity="false">
<AppenderRef ref="File-Appender-AzulMain" level="all"/>
<AppenderRef ref="Console-Appender" level="info"/>
</Logger>
<Root level="debug" additivity="false">
<AppenderRef ref="Console-Appender"/>
</Root>
</Loggers>
</Configuration>
When I use JavaUtilLogger everything works quite fine so far, I can make it create a file and print to console, however, with log4j nothing works.
I tested deleting the XML file and adding BasicConfigurator.configure() into my main-method, but it still didn't work. If I start my main-method all I get is:
Process finished with exit code 0
What is strange to me is that when I use the command java -Dlog4j.debug -cp AzulMain, it does not show me my configuration as I would expect it, but just what seems to be a very generic help message.
It is my first time, I am using a logger. Does anyone know what the problem might be?
Update:
This helped me as a first step:
BasicConfigurator replacement in log4j2
I deleted the XML-file and used the new
Configurator.initialize(new DefaultConfiguration());
Configurator.setRootLevel(Level.INFO);
And now it works at least in so far as it prints to the console. However, I am still not able to make it use the log4j2.xml file. I tried naming it log4j2-test.xml, too. (Source) It did not make a difference.
Now it works. This is how I did it.
I set up a new project, with just a main-class and added a new xml-file with a file logger only at first, then added a logger to the console, too. I deleted cache in IntelliJ and deleted the Configurator-lines in the code.
This is the new XML-file log4j2.xml that made it work:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
<Properties>
<Property name="basePath">log/${date:yyyy-MM-dd HH-mm-ss-SSS}</Property>
</Properties>
<!-- File Logger -->
<Appenders>
<!-- Console appender configuration -->
<Console name="Console-Appender" target="SYSTEM_OUT">
<PatternLayout>
<pattern>
%d{HH:mm:ss.SSS} %-5level %class{36} %L %M - %msg%xEx%n
</pattern>>
</PatternLayout>
</Console>
<RollingFile name="fileLogger"
fileName="${basePath}/Azul.log"
filePattern="${basePath}/app-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
<SizeBasedTriggeringPolicy size="10MB" />
</Policies>
<!-- Max 10 files will be created everyday -->
<DefaultRolloverStrategy max="10">
<Delete basePath="${basePath}" maxDepth="10">
<!-- Delete all files older than 30 days -->
<IfLastModified age="30d" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
</Appenders>
<Loggers>
<Root level="info" additivity="false">
<appender-ref ref="fileLogger" />
<appender-ref ref="Console-Appender" level="info"/>
</Root>
</Loggers>
</Configuration>
It seems to me to have been a mistake somewhere in the xml-file that I just couldn't figure out where it is.

Daily rolling with limit for backup files with logj4

Im usign log4j2 for logging. I need daily logging with keeping a backup of 5 days logs. My log4j2.xml looks as below. My backup files keep on increasing in number eventhough ive limited the number to 5. Where did i go wrong??
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace" monitorInterval="300">
<Appenders>
<RollingFile name="roll-by-time-and-size"
fileName="C:\\Users\\ann\\logs\\testing.log"
filePattern="C:\\Users\\ann\\logs\\testing.%d{MM-dd-yyyy}.log.gz"
ignoreExceptions="false">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss} %p %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy/>
</Policies>
<DefaultRolloverStrategy max="5"/>
<!-- <DefaultRolloverStrategy>
<Delete basePath="C:\\Users\\ann\\logs" maxDepth="1">
<IfFileName glob="C:\\Users\\ann\\logs\\test.*.log.gz" />
<IfLastModified age="3" />
</Delete>
</DefaultRolloverStrategy> -->
</RollingFile>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n">
</PatternLayout>
</Console>
</Appenders>
<Loggers>
<Root level="ALL">
<AppenderRef ref="roll-by-time-and-size"/>
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
Instead of the max consider using the delete rule.

How to use log4j2.component.properties file for org.apache.logging.log4j.core.util.Clock

According to this log4j2 configuration I am trying to set the "log4j2.component.properties" file in my NetBeans project. I have already configured my log4j2 with ASYNC_LOGGERS and one thing I particularly need is the "log4j.Clock" property. Because I get the data at a very high speed from the Servers and we expect that the logging timestamp needs to be perfect.
How can I use the "log4j2.component.properties" file in my project. Currently I created the "log4j2.component.properties" file in my default package of the project and set the values as below:
My log4j2.component.properties file
Log4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
AsyncLogger.RingBufferSize=512*1024
-DAsyncLoggerConfig.RingBufferSize=512*1024
log4j.Clock=SystemClock
My log4j2.xml file
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
<Appenders>
<RollingRandomAccessFile name="Messages-log" fileName="Log4J/Messages-${date:yyyy-MM-dd}.log"
immediateflush="true" filePattern="Log4J/Messages-%d{MM-dd-yyyy-HH}-%i.log.gz">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="500 MB"/>
</Policies>
<DefaultRolloverStrategy max="50"/>
</RollingRandomAccessFile>
<RollingRandomAccessFile name="Error-log" fileName="Log4J/Errors-${date:yyyy-MM-dd}.log"
immediateflush="false" filePattern="Log4J/Errors-%d{MM-dd-yyyy-HH}-%i.log.gz">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="500 MB"/>
</Policies>
<DefaultRolloverStrategy max="50"/>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<Logger name="Messages-log" level="info" additivity="false">
<appender-ref ref="Messages-log" level="info"/>
</Logger>
<Logger name="Error-log" level="info" additivity="false">
<appender-ref ref="Error-log" level="info"/>
</Logger>
<root level="info">
<appender-ref ref="Messages-log"/>
<appender-ref ref="Error-log"/>
</root>
</Loggers>
</Configuration>
Is this correct way of using it? I am highly confused in how to use it. I want the timestamp to be perfect and so I want to use the "log4j2.clock" parameter set to "org.apache.logging.log4j.core.util.Clock". All I want is asynchronous logging with the exact time when the record has reached. But I am getting the following exception:
ERROR StatusLogger Could not create org.apache.logging.log4j.core.util.Clock: java.lang.InstantiationException: org.apache.logging.log4j.core.util.Clock, using default SystemClock for timestamps.
Please help me.
Thanks in advance

how to configure log4j2 webapplication

Am little new to web applications, recently I was in need to employ a logging mechanism and for that I choose Log4J2, I went through there guide, and downloaded required libraries. This is what so far I did.
1. Added following jars to web-inf/lib
-- log4j-core2.1.jar
-- log4j-api-2.1.jar
-- log4j-web-2.1.jar
2. Added below xml as, log4j2.xml in java/src directory
<?xml version="1.0" encoding="UTF-8"?>
<configuration name="NONPROD" status="OFF">
<Properties>
<Property name="log-path">logs</Property>
</Properties>
<Appenders>
<Console name="console-log" target="SYSTEM_OUT">
<!-- <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n -->
<!-- </pattern> -->
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<RollingFile name="info-log" fileName="${log-path}/web-info.log"
filePattern="${log-path}/web-info-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<OnStartupTriggeringPolicy />
<SizeBasedTriggeringPolicy size="20 MB" />
</Policies>
</RollingFile>
<RollingFile name="error-log" fileName="${log-path}/web-error.log"
filePattern="${log-path}/web-error-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<OnStartupTriggeringPolicy />
<SizeBasedTriggeringPolicy size="20 MB" />
</Policies>
</RollingFile>
<RollingFile name="debug-log" fileName="${log-path}/web-debug.log"
filePattern="${log-path}/web-debug-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<OnStartupTriggeringPolicy />
<SizeBasedTriggeringPolicy size="20 MB" />
</Policies>
</RollingFile>
<RollingFile name="trace-log" fileName="${log-path}/web-trace.log"
filePattern="${log-path}/web-trace-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<OnStartupTriggeringPolicy />
<SizeBasedTriggeringPolicy size="20 MB" />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="com.demo.web.log4j2.file" level="debug"
additivity="false">
<appender-ref ref="trace-log" level="trace" />
<appender-ref ref="error-log" level="error" />
<appender-ref ref="debug-log" level="debug" />
<appender-ref ref="info-log" level="info" />
</Logger>
<Logger name="com.demo.web.log4j2.console" level="all"
additivity="false">
<AppenderRef ref="console-log" />
</Logger>
<Root level="info" additivity="true">
<AppenderRef ref="console-log" />
</Root>
</Loggers>
</configuration>
3. third and last i wrote an small web service to test logging
#Path("/register")
public class Register {
private DataManager mManager;
private static final Logger LOG = LogManager.getLogger(Register.class);
public Register(){
mManager = DataManager.getInstance();
}
#GET
#Path("/{param}")
public Response getMsg(#PathParam("param") String msg) {
LOG.error("Not supported operations");
return Response.status(Response.Status.BAD_REQUEST)
.entity("Not supported").build();
}
But in console, upon trigger get request this is all i got printed.
INFO: Server startup in 35959 ms
Not supported operations // this is not in pattern i supplied in log4j2.xml
// this is my pattern
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
I figure out this is probably due to some thing gone wrong, and am struggling to find the actual cause, being totally new to web programming, please help me out to configure my logger.
Thanks,
Techfist
Your servlet container is using some other logging framework which logs to console. Figure out which logging framework that is and use one of log4j2's bridge libraries to redirect output to your log4j2 setup.
Alright, I found the cause behind this, Issue was primarily happening due to two reasons.
First I was suppose to exclude log4j* pattern from jarsToSkip attribute in catilina property
Second, i had kept two log4j2.xml one inside web-inf other inside java/src, it was supposed to be only present at java/src. two files were not required.
Third, but not mandatory, before deployment just check if log4j2.xml is included inside web-inf/classes or not, if not then simply add it.
that's it, after following this issue was resolved now am getting proper logs.

Time based triggering policy in log4j2

I am trying to create new log files on an hourly basis. I am using TimeBasedTriggerringPolicy of lo4j2 in RollingFileAppender. Below is the sample xml configuration code i have taken from log4j2 official site.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp" packages="">
<Appenders>
<RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/$${date:yyyy-MM}/app-%d{yyyy-MM-dd-HH}-%i.log.gz">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
**
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
**
<SizeBasedTriggeringPolicy size="250 MB" />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="RollingFile" />
</Root>
</Loggers>
</Configuration>
In the interval attribute I have set 1 which signifies 1 hour.
But still my file does not roll every 1 hour.
Please help me find any mistake.
Note : I have included beta9 of log4j2 (which is the latest)
1 here indicates 1 day and not 1 hour. I have manually tested with below configuration.
<RollingFile name="T" fileName="/data_test/log/abc.log"
filePattern="/data_test/log/abc-%d{MM-dd-yyyy}-%i.log">
<PatternLayout>
<Pattern>%d{ISO8601} %-5p [%t] (%F:%L) - %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<SizeBasedTriggeringPolicy size="100 KB" />
</Policies>
</RollingFile>
For manual testing, I change the system date and time.
First, try with increasing 1 hour. The log files will be generated but not as per the expectation.
Then change the system date, increase by 1 day and then see the results.
Suppose the last log file (abc.log) on day 29-Oct is of 50 KB. Configuration size is 100 KB. If we change the day (increase by 1 day) and then run.
Then, last file will be renamed 29-Oct-(some sequence number).log (50 KB file as it is copied) and new file will be created with abc.log
I have tried this with simple servlet with below configuration in web.xml
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>log4j2.xml</param-value>
</context-param>
keep log4j2.xml in src folder. log4j2.xml is not loaded if we keep it in classpath.
Log4j documentations:
interval -> (integer) How often a rollover should occur based on the most
specific time unit in the date pattern. For example, with a date
pattern with hours as the most specific item and and increment of 4
rollovers would occur every 4 hours. The default value is 1.
You should change the filename pattern if you would like to create it every hour.
As Abid mentioned, interval value is interpreted in context of pattern that is specified as part of filePattern. It starts with lowest denomination. For example,if pattern contains S, frequency will be in millisecond. It supports the date pattern as described in detail as part of SimpleDateFormat java doc http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
You do have a non-empty log file (otherwise there is nothing to roll over)?
Note that even though the name is "TimeBased..." It will not actually roll over at the specified time, but at the first log event that arrives after the time threshold has been exceeded. Can you try with a small test program that logs something after 61 minutes or so and see if the problem still occurs?
If it doesn't roll over with the above test program, you may have found a bug. In that case please raise it on the log4j issue tracker. (Be sure to attach the test program the team can use to reproduce the issue).
Everyday day Rolling
<RollingFile name="RollingFile" fileName="logs/app.log"
filePattern="logs/app.%d{yyyy-MM-dd}.log" ...>
...
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
Everyday Hour Rolling
<RollingFile name="RollingFile" fileName="logs/app.log"
filePattern="logs/app.%d{yyyy-MM-dd-HH}.log" ...>
...
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
Everyday 5 day Rolling
<RollingFile name="RollingFile" fileName="logs/app.log"
filePattern="logs/app.%d{yyyy-MM-dd}.log" ...>
...
<TimeBasedTriggeringPolicy interval="5" modulate="true" />
Everyday 5 hours Rolling
<RollingFile name="RollingFile" fileName="logs/app.log"
filePattern="logs/app.%d{yyyy-MM-dd-HH}.log" ...>
...
<TimeBasedTriggeringPolicy interval="5" modulate="true" />
Every Month Rolling
<RollingFile name="RollingFile" fileName="logs/app.log"
filePattern="logs/app.%d{yyyy-MM}.log" ...>
...
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
Hope these cases will helps very well in understanding how filePattern and interval are related.
The time interval interpretation depends on file pattern you are using. The following configuration rolls file every second for me.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="A" target="SYSTEM_OUT">
<PatternLayout pattern="%d [%t] %-5p {%F:%L} %x - %m%n" />
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
</Console>
<RollingFile name="R"
fileName="/home/xxx/yyy/myapp.log" filePattern="/home/xxx/yyy/myapp-%d{yyyy-MM-dd-HH-mm-ss}-%i.log">
<PatternLayout pattern="%d [%t] %-5p {%F:%L} %x - %m%n" />
<Policies>
<TimeBasedTriggeringPolicy interval="1" />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="A" />
<AppenderRef ref="R" />
</Root>
</Loggers>
</Configuration>
According to your TimeBasedTriggeringPolicy configuration, logger will only populate the logs every day not every hour.
AFAIK,You can achieve the functionality by changing the filePattern from HH(Hours) to dd(Days).
I have modified your config.xml. Try This
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp" packages="">
<Appenders>
<RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/$${date:yyyy-MM}/app-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
**
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
**
<SizeBasedTriggeringPolicy size="250 MB" />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="RollingFile" />
</Root>
</Loggers>
</Configuration>
For more details check this
Hope this will workout for you too.

Categories