tags:

views:

56

answers:

5

Hi ,

How do i enable and use logging and tracing in my java program?

Thanks, magggi

+2  A: 

If you want to start using logging in java, I advise you to start with the log4j FAQ and its manual which is a good introduction.

Colin Hebert
+2  A: 

Without downloading third party libraries you could use Java Logging API - Tutorial

stacker
This would be my recommendation. I appreciate that people often recommend Log4J, perhaps with good reason, but I've generally found JDK 1.4 logging suitable for my needs without, as you say, the need for extra jars.
Ian Fairman
A: 

You may use log4j, just then I suggest you to take a look at this tutorial. I think it's a quite good and straightforward to start with.

Alexander
+1  A: 

There are a number of well-known logging APIs for Java. The most well-known is Log4J. Since Java 1.4, there's also a logging API in the standard library, in the package java.util.logging.

There is also SLF4J, which is not a logging library itself, but an interface layer which you can put between your program and a logging library such as Log4J or java.util.logging. So, you use the SLF4J API, and SLF4J passes the log messages on to whatever logging library you configure. The advantage of this is that users of your program can plug in a different logging library if they want.

Jesper
The main advantage of SLF4J is that when you start using different components, they often end up using different logging frameworks. Hopefully slf4j will alleviate this.
Joeri Hendrickx
A: 

If you want you can use a logger package like Commons Logging or Log4J or any other.

For tracing, you can use Jconsole, a tool that comes packaged with JDK. I use this in my application for monitoring jobs, memory utilization etc.

Amit