aspose file tools*
The moose likes Other Open Source Projects and the fly likes Java Logging Or Log4J Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Java Logging Or Log4J" Watch "Java Logging Or Log4J" New topic

Java Logging Or Log4J

Ashok Talluri
Ranch Hand

Joined: Sep 24, 2001
Posts: 31
which Logging API should I use in my project?
Java Logging API or Apache Log4J?
John Mill

Joined: Feb 12, 2002
Posts: 11
I was told by somebody that the Java Logging is 90% log4j anyway, (possibly not a trustworthy source ;-> . I used log4j on a v. large project and it worked fine once we'd established the rules for its use. Based on the experience of that project though I'd suggest that briefing ALL developers on how it is to be used is essential or it becomes even more problematic than the thousands of System.out calls that we were finding before...
Suhel Rizvi

Joined: Feb 19, 2002
Posts: 7
We also are using log4j on our project ad it is proving invaluable. It allows us to log to stdout as well as to files and it can be configured from one config file so various packages or even classes from your software are logged, not logged, logged to different files or in different formats.
It seems its capable for a lot more than we are currently using it for as well.
I definitely agree with briefing all developers on its use at the start of the project to avoid all the system.outs
Doug Wang
Ranch Hand

Joined: Oct 05, 2001
Posts: 445
As John said, the Java Logging is 90% log4j. So it makes no difference choosing Java Logging or log4j. The only difference is, when you use JDK1.4, you need not extra effort for getting logging API.
Thanks John for your kind advice.

Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep
Guillaume Compagnon
Ranch Hand

Joined: Aug 09, 2001
Posts: 106
Log4J is hugely used in the industry, while Java Logging is new but ... it is the standard.
as someone tells , Java Logging & Log4J are similar except for the constant of severity...
the problem and there was a polemic ... is that Log4J is IBM stuff (fusionning in the Jakarta project) and Java Logging is Sun & JCP initiative.
if I were U, I will use the standard: Java Logging
which is present in JDK 1.4

Ashok Talluri
Ranch Hand

Joined: Sep 24, 2001
Posts: 31
Thanks to you all for your suggestion.
Ravi Veera
Ranch Hand

Joined: Jun 23, 2001
Posts: 127
Here is the original critique of the JSR 47 from log4j's point of view.
This is now obselete.
After Subsequent changes to the JSR a revised critique was put out which highlights the remaining trivial differences between the two,
If your logging needs are simple it doesn't really matter which one you use.
With Log4j you will probably get new features/updates/changes/bugfixes to you much faster. With the logging API you will have to probably wait for the next iteration of the JDK from sun.
timothy zimmerman
Ranch Hand

Joined: Jun 26, 2001
Posts: 149
The java logging API is new in jdk1.4. Up until this I would have said that Log4J was most widely used logging API (and may still be?). I have not looked in depth at the Java Logging API but I have heard from a few sources that it is very comparable to Log4J (it seems from the other posts that others have heard similar)
One reason to go with the java logging API may be that you need not keep track of the separate jars etc. Each time you move forward to new jdk you will move forward to new logging API.
Nicholas Lesiecki

Joined: Mar 12, 2002
Posts: 13
I would agree, we used Log4J before JDK Logging came out, but now it just seems like an extra dependency to track and manage.
Nicholas Lesiecki

Principal Software Engineer<br />eBlox, Inc.<br />(520) 615-9345 x104<br />Check out my new book!:<br /><a href="" target="_blank" rel="nofollow"><br />Java Tools for Extreme Programming: Mastering Open Source Tools, including Ant, JUnit, and Cactus<br /></a><br /><a href="" target="_blank" rel="nofollow">More Info</a><br /> <br /><br />Check out my article on <a href="" target="_blank" rel="nofollow">AspectJ.</a>
Craig Demyanovich
Ranch Hand

Joined: Sep 25, 2000
Posts: 173
I'm glad that Ravi Veeraghanta mentioned that log4j will likely be "refreshed" on a more regular basis than the logging API in 1.4; his point is worth considering.
One further point worth considering is that log4j works with JDK 1.1 and beyond, while the new logging API is for 1.4 and beyond. Hence, if you can't adopt 1.4 for your development, log4j is an excellent tool to have in the toolbox! Keep up the great work on the Jakarta projects, team.
Nicholas Lesiecki

Joined: Mar 12, 2002
Posts: 13
Good point Craig! We're planning to switch to JDK1.4 logging where I work, but we're keeping Log4J in Cactus because of it's wider compatibility across JDKs. I wonder if Sun considered adding it as a separate jar?
Nicholas Lesiecki
Nelson David

Joined: Oct 01, 2002
Posts: 13
Hi all,
Seems u people are very experience in using log4J, I am using log4j for the first time, I have one question in mind, how to get the Logger instance, should I have to do Logger logger=Logger.getLogger(...)in each file or should I initialize it in one file and provide a bean like method to retreive the logger instance where ever in the project it is required
Kees van Oosterhout
Ranch Hand

Joined: Jul 08, 2002
Posts: 34
I have too made the choice between Log4j and the Logging API. I have chosen Log4j because,
- Many of the systems are using JDK 1.3.1 or less
- Log4j offers a lot more functionality
- The configuration can be done by a xml file, which is a standard

"'ve got to ask yourself one question, Do I feel lucky?"
Dhananjay Inamdar
Ranch Hand

Joined: Jan 27, 2003
Posts: 130
Hi Nelson,
this in refernce to your question of making the instances of logging. That is true you have to make a instance in your every file and canot make only one instance from one common file.
As while logging these instance considering the name of class where it is instantiated and appends the method name to this class name while putting it in the log.
So, better and safer way is to instantiate the log in every file and then use it.

Just like you, struggeling to get the right solutions!<br /> <br />Sun Certified Java Programmer 1.5<br /> <br />Target - SCWCD
Sean Sullivan
Ranch Hand

Joined: Sep 09, 2001
Posts: 427
I have used java.util.logging and Log4j.
Log4j is more powerful. It is more configurable. It has more
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Any plans to write an article on this. It would be great if you do write one.
I liked your DAO article.

Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
I know that this is an old thread, but I would recommend the use of Commons Logging. It's a very thin wrapper around log4j and J2SE 1.4 logging. Write your code to that API and then you can switch between the two at the flick of a switch. Here's some more detail.
Sean Sullivan
Ranch Hand

Joined: Sep 09, 2001
Posts: 427
I have written an outline for an article that discusses
Log4j and java.util.logging.
I have not decided if I will finish it.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Hi Simon
Can you please look at the post I made on "Other APIs" forum,
and reply?
Basically I used Jakarta Commons Logging to see how it works and seems to work fine but I wanted to know if it is compatible with JDK1.2/1.3? Of course we have JDK1.4 then there is no need to ask as anyways it will use JDK1.4 logging if Log4J isn't there and in that case it will be working fine but what if we have JDK1.2/1.3 and Log4J's older version (somehow!) and we want things to work...
Please reply to this post or that one and initiate "close of thread" if applicable to avoid multiple posts.
Consider Paul's rocket mass heater.
subject: Java Logging Or Log4J