Java – modify how compositerollingappender renames files

I've seen a lot of problems about log4j different Appenders here, but it seems that there are no problems that can solve the problems I encounter If you repeat it anywhere, please apologize

I use composite rolling appender in our application because we need to scroll log files according to time and size This is exactly the same as the publicity, but we finally got the following documents:

myapp.log
myapp.log.2010-12-11
myapp.log.2010-12-11.1
myapp.log.2010-12-12

Can I change the format of log4j rename file? I'm sure I missed an elusive property For example, in the above case, I want to look like:

myapp.log
myapp-2010-12-11.log
myapp-2010-12-11.1.log
myapp-2010-12-12.log

The point here is that expansion is still Why did you ask? Because our application administrators complain that they can't just double-click the file to open it (I know, I know) If they all have Log extension, then this is not the case

Thank you in advance

Solution

Compositerollingappender does not support the functionality you want It is very limited in determining (at startup) whether an appropriate log file to attach already exists It only supports adding date and number at the end of the static name of the configuration

You can try using log4j extras compositetriggingpolicy, but I didn't know that rollingpolicy would include dates and windows

The administrator's choice is to give up the file size limit so that rollingfileappender can be used with timebasedlollingpolicy

<param name="FileNamePattern" value="MyApp.%d{yyyy-MM-W}.log" />

Or rename the file with the current name or run a cron job, but remember that you cannot rename the file until the next day (otherwise you will get a file name conflict)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>