Search code examples
javalog4jlog4j2configuration-files

log4j.properties to log4j2 log2.xml


what is the equivalent log4j.properties file in log4j2.xml to this file:

log4j.rootLogger=INFO, DEF
log4j.appender.DEF=org.apache.log4j.DailyRollingFileAppender 
log4j.appender.DEF.File=${catalina.home}/webapps/myApp/logs/hasan.log 
log4j.appender.DEF.DatePattern='.'dd-MM-yyyy

# layout-config fro root-logger
log4j.appender.DEF.layout=org.apache.log4j.PatternLayout 
log4j.appender.DEF.layout.ConversionPattern=%d{ISO8601} UTC [%25.25t] %-5p %25.25c %x - %m%n

Solution

  • Here is your equivalent log4j2.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <Configuration>
        <Appenders>
            <RollingFile name="DEF" 
                         fileName   ="${sys:catalina.home}/webapps/myApp/logs/hasan.log" 
                         filePattern="${sys:catalina.home}/webapps/myApp/logs/hasan.log.%d{dd-MM-yyyy HH-mm-ss}">
                <PatternLayout pattern="%d{ISO8601} UTC [%25.25t] %-5p %25.25c %x - %m%n"/>
                <TimeBasedTriggeringPolicy modulate="true" />
            </RollingFile>
        </Appenders>
        <Loggers>
            <Root level="INFO" >
                <AppenderRef ref="DEF" />
            </Root>
        </Loggers>
    </Configuration>