Logging using slf4j, log4j in Maven application

How to start logging in Maven application? How to add required dependencies?

How to start logging in Maven application? The technique is the same in Java SE and Java EE applications. Goto pom.xml and add these dependencies:

 

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
</dependency>

 

Next add to classpath log4j.properties file.

 

Inside class you want to do logging add this attribute:

 

private static final Logger logger = LoggerFactory.getLogger(Main.class);

 

And then simply call logger methods.