tags:

views:

589

answers:

3

For example, the first time I run an application (or immediately after I clear out the /logs directory), I want log4j to write the application's logs to a file called log.0. Then, I exit the application and restart it, I want the logs to be written to log.1. And so on.

I would like to keep this in the configuration file, although if I can't, I guess I could always do it in my application, when log4j is set up.

Is this possible? If so, how?

A: 

Off the top of my head I don't think this is possible from with Log4j. Maybe when you shut the application down you could rename the .log file so next time you start up a new log file is created.

Karl
If that's the case, I'm somewhat disappointed. log4j meets all of my needs, and performs well. I just want to be able to group my logs by execution, instead of by date or file size.
Thomas Owens
I once wrote an additional adapter for log4j (long story) the source code is really easy to read and well documented sure it will not take you long to implement this feature :-)
Karl
+7  A: 

May be this is what you are looking for

http://veerasundar.com/blog/2009/08/how-to-create-a-new-log-file-for-each-time-the-application-runs/

Edit:I got one more solution! But no idea whether it works or not,but you can try http://www.mail-archive.com/[email protected]/msg02132.html

Umesh
Yes, I think creating a custom appender is the way to go.
Pascal Thivent
+2  A: 

See logback's manual on uniquely named files (by timestamp). Sigh.

Ceki