Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

log4j vs JDK logging

 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one tell me why log4j is more popular than JDK Logger API. Yes, I know that log4j work with the older JDKs.
 
sunitha reghu
Ranch Hand
Posts: 937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check this thread
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunitha
The thread is dated 2001, not sure if it holds good today.
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's been around longer.
 
Mike Wang
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradeep Bhat:
Can any one tell me why log4j is more popular than JDK Logger API. Yes, I know that log4j work with the older JDKs.

1. Log4j come into word earlier than JDK logging API.
2. Log4j works for older JDK.
3. Log4j is more configuarable than JDK logging API.
4. Log4j has proven product quantity. etc. JBoss use it!
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Log4j is more configuarable than JDK logging API.

Could you please elaborate more?
 
vasu maj
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Log4j is used by default as people have been using it for a long time. Java's logging api is relatively new and it needs to be really far better for people to take notice. I don't know if it is the case. It looks like it is not.

Thanks,
Vasu
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vasu maj:
Java's logging api is relatively new and it needs to be really far better for people to take notice.
Actually, I strongly believe that the JDK Logging API will become the de facto standard because it's already there. The old-timers may choose Log4J over the standard Logging API on the basis of technical merit, but the newcomer will pick what's taught in the textbook of "Java Programming 101."
In fact, I didn't think twice using java.util.logging over Log4J in my current/past project. We didn't need the extra functionality provided by Log4J and valued the ease of use of the java.util.logging package.
Obviously your mileage may vary (and it almost certainly does), but the standard Logging API is probably already sufficient for most "enterprise" web applications out there.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I has read that JDK loggin perform better than log4j.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We didn't need the extra functionality provided by Log4J

what is that extra functionality?
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
J2SDK logging performs well with minimal configuration.
That said we're using a logging class we rolled ourselves (but it was created by someone coming from C who might not have known there was integrated logging functionality in Java now).
It's simple, fast, and does what we want it to without having to configure a big logging framework for simple things.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradeep Bhat:
what is that extra functionality?

More flexible configuration options like logging to a JDBC connection, to Windows NT event logs, to SMTP servers, over a TCP socket, etc.
Oh, I forgot one: rolling log files based on date instead of just file size.
[ April 15, 2004: Message edited by: Lasse Koskela ]
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeroen Wenting:
It's simple, fast, and does what we want it to without having to configure a big logging framework for simple things.
That sounds very much like the reasoning I did for using the Logging API instead of Log4J...
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question regarding disabling logging
Isn't it better to have


rather than

with logging disabled in some properties file.
Note that the first approach avoids method calls. :roll:
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In theory, yes, it would be better from a performance point of view.
However, for most applications/components I would prefer readability over micro-optimization. With a reasonable certainty, the additional method calls the logging framework makes for determining whether the given message should be logged or ignored is not a bottleneck.
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it make sense to provide a facility whereby logger statements can also be removed during deployment like asserts?
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by karthik Guru:
Does it make sense to provide a facility whereby logger statements can also be removed during deployment like asserts?

I think that assert statements are implemented usinf some sort of if boolean statements. correct me if I am wrong.
[ April 15, 2004: Message edited by: Pradeep Bhat ]
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradeep Bhat:

I think that assert statements are implemented usinf some sort of if boolean statements. correct me if I am wrong.
[ April 15, 2004: Message edited by: Pradeep Bhat ]

oops I thought that they are not even compiled into the bytecode when compiled with some special javac option.
I checked up, You are correct.They can be switched on or off at runtime using the java command line option. So they also incur a boolean check.
 
friso dejonge
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh well everyone fell over this statement so i may as well:
Does it make sense to provide a facility whereby logger statements can also be removed during deployment like asserts?

my question is, have you ever worked in a situation where you have to bugfix a system on a server where you are allowed to see the logfiles, but nothing more ? (no configuration, server names, directories etc) As a person who maintains an application you need to have as much debugging statements as possible, otherwise you cannot fix any bug.
Therefore it may well be possible to get all logger statements out, but hey, give the bugfixers a chance to fix all our bugs.
 
Sean Sullivan
Ranch Hand
Posts: 427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Log4j provides more useful appenders.
For example, Log4j provides the SMTPAppender
I ported Log4j's SMTPAppender to java.util.logging
The code is available online: http://smtphandler.sourceforge.net/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic