Log4j.xml create & 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=”www.jakarta.apache.org/log4j/” debug=”false”>

<appender name=”fileAppender” class=”org.apache.log4j.FileAppender”>
<param name=”Threshold” value=”INFO” />
<param name=”File” value=”NewGeneratedLogFile.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”);
}
}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s