wood burning stoves 2.0*
The moose likes Other Java Products and Servers and the fly likes Slf4j Logger Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "Slf4j Logger" Watch "Slf4j Logger" New topic

Slf4j Logger

Pawan Singh

Joined: Jun 05, 2012
Posts: 9

I want to add Logger in my Application. I want every description of application or flow in my XXX.log file.
but since I am very new to it, I don't know anythink about it.
I added slf4j-api.jar + slf4j-simple.jar in my lib folder .... now after that what should I do for proper working of logger.

I also used in my classes as following code.

Logger logger=LoggerFactory.getLogger(HelloWorldAction.class);

other than this I don't know any think, please guide me.
please help me.
Joe Ess

Joined: Oct 29, 2001
Posts: 8839

Have you read the documentation? If so, what specific problem or question do you have?

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Pawan Singh

Joined: Jun 05, 2012
Posts: 9
First of all Thanks for your quick reply.
I already read the documentation. ok, here is what I have done.

1- slf4j-api-1.6.6.jar, slf4j-simple-1.6.6.jar in my lib folder of WEB-INF/lib
2- log4j.properties file under src folder. ie inside classes foder. "src\log4j.properties"
log4j.properties consist of:
# [
log4j.rootLogger=DEBUG, stdout, R
#log4j.rootLogger=ERROR, stdout, R
log4j.appender.R.layout.ConversionPattern=%d %p %t %c - %m%n
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
# ]
3- I used it as in my code like:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HelloWorld {
public static void main(String[] args) {
Logger logger = LoggerFactory.getLogger(HelloWorld.class);
logger.info("Hello World");
logger.debug("In debug"); } }

4- What I want: whole logging output should be write to log4j.log file as mentioned in log4j.properties file
5- What's Happening whole logging out is visible in ide console, but not in log4j.log file. In log4j.log file only a very small output is there about 30-40 lines..which is meaningless.

Please help me , I think there is some mistake in log4j.properties file.
Joe Ess

Joined: Oct 29, 2001
Posts: 8839

Pawan Singh wrote:First of all Thanks for your quick reply.
I already read the documentation. ok, here is what I have done.

You must have missed the line:

As mentioned previously, SLF4J supports various logging frameworks. The SLF4J distribution ships with several jar files referred to as "SLF4J bindings", with each binding corresponding to a supported framework.

Binding for log4j version 1.2, a widely used logging framework. You also need to place log4j.jar on your class path.

I assume this is how one would tell SLF4J to use Log4j.
Harish Onkarappa

Joined: Oct 31, 2012
Posts: 1

change it to


and use the log4j version greater than 1.2.12. it wont support if the version is less then that.
I agree. Here's the link: http://aspose.com/file-tools
subject: Slf4j Logger
Similar Threads
Hibernate main" java.lang.NullPointerException
Doubt in Hibernate Sample Application
Create dropdown listbox menu Using JSP and AJAX control
want to implement sorting logic in my project with jsf
Hibernate Query