0

I need to configure log4j.xml in such a way that the current log file with this format (example trans-20170517) will change daily and saves the previous day file.

Example of what I want of logs to produce: trans-20170516.log (yesterday) trans-20170517.log (current log)

Please see below for my xml format:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
    <Properties>
        <Property name="log-path">C:/Users/glopega/Desktop/ItemError</Property>
        <Property name="log-file-name">transactions</Property>
    </Properties>
    <Appenders>
        <RollingFile name="RollingFile" fileName="${log-path}/${log-file-name}-${date:yyyyMMdd}.log" filePattern="${log-path}/${log-file-name}-%d{yyyyMMdd}.log">
            <PatternLayout>
                <pattern>%d{yyyy-MM-dd kk:mm:ss},%m%n</pattern>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy interval="1"
                    modulate="true" />
                <OnStartupTriggeringPolicy />
            </Policies>
            <DefaultRolloverStrategy max="999" />
        </RollingFile>
    </Appenders>
    <Loggers>
        <Logger name="root" level="debug" additivity="false">
            <appender-ref ref="RollingFile" level="debug" />
        </Logger>
        <Root level="debug" additivity="false">
            <AppenderRef ref="RollingFile" />
        </Root>
    </Loggers>
</Configuration>
George
  • 263
  • 5
  • 17
  • Read about RollingFileAppender – Jens May 17 '17 at 09:57
  • http://stackoverflow.com/questions/192456/setting-a-log-file-name-to-include-current-date-in-log4j – Sagar Gandhi May 17 '17 at 10:02
  • Possible duplicate of [Setting a log file name to include current date in Log4j](http://stackoverflow.com/questions/192456/setting-a-log-file-name-to-include-current-date-in-log4j) – Sagar Gandhi May 17 '17 at 10:03
  • Please refer to my xml configuration: My current xml config just create another log file for previous day but it did not change the name of current log file. what i want is, it will create another file, and rename current log file to current date – George May 17 '17 at 10:06

0 Answers0