Monday, June 11, 2012

log4j in maven project

Adding support for log4j is realized via maven dependency. You have to edit pom.xml file, and add these lines:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
...................
  <dependencies>
.................
    <dependency>
      <groupId>commons-logging</groupId> 
      <artifactId>commons-logging</artifactId> 
      <version>1.1.1</version> 
       <scope>compile</scope>
    </dependency>
 
    <dependency> 
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.16</version>
      <scope>compile</scope>
    </dependency>
......
  </dependencies>
 
<build>
....
</build>
</project> 


Where to place the configuration file log4j.properties?
The correct location is src\main\resources folder.


How to configure log4j? 
Here you could find examples of log4j.properties.

No comments:

Post a Comment