Is it possible to configure log4j to create a new file with every run of the application?

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


Solution with log4j2:

        <RollingFile name="RollingFile" fileName="${log-path}/GScraper.log"
                 filePattern="${log-path}/GScraper_%d{yyyy-MM-dd}_%i.log">
        <ThresholdFilter level="WARN" onMatch="ACCEPT" onMismatch="DENY"/>
        <PatternLayout>
            <pattern>%level\t%d{yyyy-MM-dd HH:mm:ss} %c: %m%n</pattern>
        </PatternLayout>
        <Policies>
            <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
            <SizeBasedTriggeringPolicy size="32 MB" />
            <OnStartupTriggeringPolicy/>
        </Policies>
    </RollingFile>

Note OnStartupTriggeringPolicy and %i in filePattern. This way, Log4j will create new log file with index each time you run the App.

Tags:

Java

Log4J