logo

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.


comments powered by Disqus

rss

Free online Java web application examples

Want to develop whole web applications which use database, security and more? See my github account, where are lot's of example projects:
github

Search