aspose file tools*
The moose likes Java in General and the fly likes J2SE Logging Framework Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "J2SE Logging Framework" Watch "J2SE Logging Framework" New topic
Author

J2SE Logging Framework

Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
Dear all,
We know that logging is very useful to help us in developing phase.
We can know the defect or the success of our code.
And we can choose one of logging mode we want ( FATAL, ERROR, WARNING, INFO or DEBUG).

Example for developing phase we choose DEBUG mode, and we have a lot of logging statements in our code.
After our code is 'live', we still don't remove those statements and we choose FATAL mode.
Will it impact to the overall performance of our application?

Correct me if I am wrong...

thanks
daniel
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30293
    
150

Daniel,
Java still has to build the string to log. This is usually a minimal cost and not worth worrying about. If you are doing something where you cannot afford this, try something like:

The best way to find out is to try running your application with and without logging and see if there is a noticeable performance difference.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Jeanne is absolutely right: Reality beats theory every time


Java Regular Expressions
Scott Dunbar
Ranch Hand

Joined: Sep 23, 2004
Posts: 245
To me this is one area that the Java logging API falls down. You really need something external to determine if you should log or not.

The Jakarta Commons Logging api is a thin veneer over standard logging mechanisms (such as 1.4 logging or Log4J) and give you the flexibility to do something like:



The advantage is that you can turn debug logging on and off external to the program by modifying the config file.

The call to check if debug logging is enabled does give a tiny bit of overhead. But it is well worth it, in my mind, to allow you to turn on debugging when an application at the customer site is barfing. If you construct your logging correctly you can even create a debug log for a single class.


<a href="http://forums.hotjoe.com/forums/list.page" target="_blank" rel="nofollow">Java forums using Java software</a> - Come and help get them started.
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Originally posted by Scott Dunbar:
To me this is one area that the Java logging API falls down. You really need something external to determine if you should log or not.

The Jakarta Commons Logging api is a thin veneer over standard logging mechanisms (such as 1.4 logging or Log4J) and give you the flexibility to do something like:



The advantage is that you can turn debug logging on and off external to the program by modifying the config file.



OK, what am I missing here!!
If we are talking about J2SE logging, cant I just do

And turn logging off or on by specifying the level for that heirarchy of loggers in logging.properties file.


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: J2SE Logging Framework