Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Logging Or Log4J

 
Ashok Talluri
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which Logging API should I use in my project?
Java Logging API or Apache Log4J?
 
John Mill
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Guillaume Compagnon
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to you all for your suggestion.
 
Ravi Veera
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the original critique of the JSR 47 from log4j's point of view.
http://jakarta.apache.org/log4j/docs/critique.html
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,
http://jakarta.apache.org/log4j/docs/critique2.html
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
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would agree, we used Log4J before JDK Logging came out, but now it just seems like an extra dependency to track and manage.
Cheers,
Nicholas Lesiecki
 
Craig Demyanovich
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Craig
 
Nicholas Lesiecki
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Cheers,
Nicholas Lesiecki
 
Nelson David
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
regards
Nelson
 
Kees van Oosterhout
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dhananjay Inamdar
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sean Sullivan
Ranch Hand
Posts: 427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have used java.util.logging and Log4j.
Log4j is more powerful. It is more configurable. It has more
functionality.
http://www.pjug.org/logging072002.ppt
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sean,
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
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Simon
 
Sean Sullivan
Ranch Hand
Posts: 427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pradeep,
I have written an outline for an article that discusses
Log4j and java.util.logging.
I have not decided if I will finish it.
-Sean
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Simon
Can you please look at the post I made on "Other APIs" forum,
here
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.
Regards
Maulin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic