Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8975915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:59:53+00:00 2026-06-15T18:59:53+00:00

I have the following log4j2.xml file: <?xml version=1.0 encoding=UTF-8?> <configuration status=OFF> <appenders> <RollingFile name=testLog

  • 0

I have the following log4j2.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="OFF">
  <appenders>
    <RollingFile name="testLog" fileName="test.log" filePattern="" append="false">
      <PatternLayout pattern="[%t] %-5level - %msg%n%n"/>
    <SizeBasedTriggeringPolicy size="5mb" />
    </RollingFile>
  </appenders>
  <loggers>
    <logger name="TestsLogger" level="trace" additivity="false">
      <appender-ref ref="testLog"/>
    </logger>
    <root level="debug">
      <appender-ref ref="testLog"/>
    </root>
  </loggers>
</configuration>

How can I modify this configuration such that

  1. Instead of overwriting the same logfile over and over again a new file is created after the 5mb limit has been reached. It would be nice to have something like test1.log, test2.log and so on.
  2. How can I limit the number of partial log files created in 1.? What I want to achieve is a scheme like the following:

    creating test1.log [present log files: test1.log]
    test1.log - 5mb limit reached
    creating test2.log [present log files: test1.log, test2.log]
    test2.log - 5mb limit reached
    creating test3.log [present log files: test2.log, test3.log]
    test3.log - 5mb limit reached
    creating test4.log [present log files: test3.log, test4.log]
    and so on
    

Does anyone know, how to achieve something like that? Of course it would be nice, if something like that was possible with log4j2 alone. But maybe there is a way to combine log4j2 with some kind of external program that would run alongside the main Java application and delete superfluous log files, while keeping the two last log files intact. So if anyone has at least a suggestion for 1., it may be already, what I’m looking for. Because I may be able to write a program for the 2nd part. Of course it would be awesome, if the 2nd part could be done with log4j2 as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:59:54+00:00Added an answer on June 15, 2026 at 6:59 pm

    I never used log4j2 so far but the documentation of the RollingFileAppender gives you a lot of configuration examples.

    Interesting for you seams to be something like this (using DefaultRolloverStrategy):

    <RollingFile name="RollingFile" fileName="logs/app.log"
                 filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
      <PatternLayout>
        <pattern>%d %p %C{1.} [%t] %m%n</pattern>
      </PatternLayout>
      <Policies>
        <SizeBasedTriggeringPolicy size="5 MB"/>
      </Policies>
      <DefaultRolloverStrategy max="20"/>
    </RollingFile>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following plist: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
I have the following log4j.xml configuration: <log4j:configuration> <appender name = CONSOLE class = org.apache.log4j.ConsoleAppender>
I have the following in log4j.xml file, when I run my application. Only error
Suppose i have a configuration file like the following to start my application. How
I have following XML configration i would like to convert to java property file.
I have the following log4j.properties file: log4j.rootLogger=DEBUG,A1,A2,A3 log4j.appender.A1=org.apache.log4j.RollingFileAppender log4j.appender.A1.Threshold=DEBUG log4j.appender.A1.File=log.out log4j.appender.A1.MaxFileSize=100KB log4j.appender.A1.MaxBackupIndex=1 log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%p
I have the following for my log4j DSL configuration in Grails 1.2: log4j =
I have implement a log4j.xml file having two loggers. Both EventLogger and ErrorLogger logged
I have the following syntax problem. I have a jar file that is created
I have the following log4j.properties file, for an application deployed in WebSphere Portal: log4j.rootLogger=DEBUG,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.