אחת111
אחת111

Reputation: 11

Log4j - file name index and rolling files

In our applications we use Log4j logger.

For our log files we have 2 requirements:

  1. The files are written in different folders according to hour change(every hour I open a new folder)

The index in the name file of those files should be sequential, that is, after I open a new folder I want to start from index +1 of the last file in the previous folder.

My current pattern is:

<RollingRandomAccessFile name="RollingFile" append="true"
    filename="${sys:logDir}/${sys:logAppName}_${sys:logSessionData}_LAST.logmx"                   
    filePattern="${sys:logDir}/$${date:yyy-MM-dd-HH}/${sys:logAppName}_${sys:logSessionData}_#%i.logmx">   

Currently the file name index (i) is being reset for each folder.

2. The rolling of the files should goes from oldest file to newest between all folders.

My current pattern is:

<defaultRolloverStrategy max=10000>

For example, for  10 folders that contain together 10000 files, the intention is that the oldest file (index 1) will be rolled over.

Currently, the rolling is happening for current folder (newest folder). Can someone give an idea how to define log4j.xml or something else to create such logs files with rolling.

Is it possible? Can you give me an example?

Upvotes: 1

Views: 45

Answers (0)

Related Questions