File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

J2SE Logging Framework

 
Fisher Daniel
Ranch Hand
Posts: 582
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 33684
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne is absolutely right: Reality beats theory every time
 
Scott Dunbar
Ranch Hand
Posts: 245
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic