Sunday, 13 September 2015

Log4j file work.

Jar : log4j-1.2.17.jar to be add.
log4j.xml  :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

   <appender name="fileAppender" class="org.apache.log4j.FileAppender">
      <param name="Threshold" value="INFO" />
      <param name="File" value="NewGenerated
LogFile.log"/>
      <param name="Append" value="flase" />
      <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss}  [%c] (%t:%x) %m%n" />
      </layout>
   </appender>

   <root>
   <level value="INFO"/>
      <appender-ref ref="fileAppender"/>
   </root>
  
</log4j:configuration>


Log4j.java
package testing;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.junit.Test;

public class Log4j {
    static final Logger logger = LogManager.getLogger(Log4j.class.getName());
   
    @Test
    public void logTest(){
        DOMConfigurator.configure("log4j.xml");
       
        logger.info("# # # # # # # # # # # #  # # # # # # # # # # # # # ");
        logger.info("TEST Has Started");
    }
}

No comments:

Post a Comment