Understanding of Max Backup Index in log4j framework

15,882

Solution 1

You may want to use a custom FileNamePattern, using %i which is the index of the file :

#Appender
log4j.appender.f = org.apache.log4j.RollingFileAppender
log4j.appender.f.File = C:\\Users\\myname\\Desktop\\Test.txt
log4j.appender.f.rollingPolicy.FileNamePattern=C:\\Users\\myname\\Desktop\\Test%i.txt

Solution 2

That parameter is defining how many files will be kept after deleting from rollback policy:

the official doc states:

maxBackupIndex: Maximum number of backup files to keep.

in your case that will happen every time the loger file reaches the 100KB you defined...

Share:
15,882

Related videos on Youtube

Armer B.
Author by

Armer B.

Java Developer

Updated on July 13, 2022

Comments

  • Armer B.
    Armer B. almost 2 years

    I will introduce to you a simple source example:

    #Level
    log4j.rootLogger = DEBUG, f
    
    #Appender
    log4j.appender.f = org.apache.log4j.RollingFileAppender
    log4j.appender.f.File = C:\\Users\\myname\\Desktop\\Test.txt
    
    #File size
    log4j.appender.f.MaxFileSize = 100KB
    log4j.appender.f.MaxBackupIndex = 1
    

    I understand the working of source and see that the output result will be "logger messages" written in file Test.txt. And when I have reached the max file size of 100KB it will be created new file with name Test.txt.1

    My simple issue is can I generate new file to be with name Test1.txt no Test.txt.1

    Best regards,
    D.Balamjiev

  • Armer B.
    Armer B. about 7 years
    Yes I understand that, but is it possible to manage the output file name?