Tuesday, April 16, 2019

log4j2

 <?xml version="1.0" encoding="UTF-8"?>  
 <Configuration status="warn">  
      <Properties>  
           <Property name="basePath">C:\\Users\\Mitturaj.h\\Selenium-Learning\\Selenium-Learning\\test-output  
           </Property>  
      </Properties>  
      <Appenders>  
           <RollingFile name="fileLogger" fileName="${basePath}/app-info.log"  
                filePattern="${basePath}/app-info-%d{yyyy-MM-dd}.log">  
                <PatternLayout>  
                     <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n  
                     </pattern>  
                </PatternLayout>  
                <Policies>  
                     <TimeBasedTriggeringPolicy interval="1"  
                          modulate="true" />  
                </Policies>  
           </RollingFile>  
           <RollingFile name="Logger" fileName="${basePath}/app-log.log"  
                filePattern="${basePath}/app-info-%d{yyyy-MM-dd}.log">  
                <PatternLayout>  
                     <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n  
                     </pattern>  
                </PatternLayout>  
                <Policies>  
                     <TimeBasedTriggeringPolicy interval="1"  
                          modulate="true" />  
                </Policies>  
           </RollingFile>  
           <Console name="console" target="SYSTEM_OUT">  
                <PatternLayout  
                     pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />  
           </Console>  
      </Appenders>  
      <Loggers>  
           <!-- file-logger is ref to rolling file name: fileLogger -->  
           <Logger name="apachepoi" level="debug" additivity="true">  
                <appender-ref ref="fileLogger" level="debug" />  
           </Logger>  
           <!-- logger ref is here reference to Rolling File name:Logger -->  
           <Logger name="log4j2" level="debug" additivity="true">  
                <appender-ref ref="Logger" level="debug" />  
           </Logger>  
           <Root level="debug" additivity="false">  
                <appender-ref ref="console" />  
           </Root>  
      </Loggers>  
 </Configuration>  


 package log4j2;  
 import org.apache.logging.log4j.LogManager;  
 public class LogIt {  
      private static final org.apache.logging.log4j.Logger LOGGER=LogManager.getLogger(LogIt.class.getName());  
      public static void main(String[] args) {  
           LOGGER.info("Loggin here");  
      }  
 }  


No comments:

Post a Comment