wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Properly shutting off logging Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Properly shutting off logging" Watch "Properly shutting off logging" New topic
Author

Properly shutting off logging

Norbert Lebenthal
Ranch Hand

Joined: Sep 23, 2010
Posts: 74
hi

I've been using a bit of jdk logging and I would like to disable it for the "final" version

up to now I did something like this in my code:


I then call it with the various logger I've.

Yet I'm not happy with it:
- enabling logging means changing the code (and figuring out where first)
- it doesn't work in all cases, I suspect it to handle badly multithreaded access to the logger

In the end, do you think it's possible to just include some logging configuration file in the jar provided ?

thanks in advance
best
norbert
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5514
    
  13

Hi Norbert,

I followed another approach: in my main-method I call an initLogging-method which initializes the logging level for each logger with a static constant representing the logging level. The level can easily be changed, just use another enum value and you are done, no other changes required.

The Java util logging API isn't the most developer-friendly This is the code I used:


Hope it helps!
Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Norbert Lebenthal
Ranch Hand

Joined: Sep 23, 2010
Posts: 74
hi Roel

thanks for your blazing fast answer

however, even with your line, I still have some issue with logging: even if turned off at init time, when someone select a file in the browse dialog then the logging in the FileDatabaseManager is outputted.

When I don't select a file in the same dialog, then the logging in the FileDatabaseManager isn't done

in fact I'm seriously considering dumping all logging because of the time I've lost in this turning off business.

I even wrote an example for it:


=> launching it, using the browse dialog to select a file (using the filter on .db file) triggers some logging to be seen afterwards. Using the default filter (all files ok) doesn't trigger this behavior. Feels really buggy and crazy to me...
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5514
    
  13

Hi Norbert,

To be honest: I don't get the problem. When I select a file in your test class I get the following output:

So this line getLogger().info("logger disabled"); is not shown in the console, which is good because you disabled it. Also this line getLogger().info("file selected " + locationField.getText()); produces no output in the console, again a good thing

The other lines in the output are present because you use System.out.println which has nothing to do with java util logging

Kind regards,
Roel
Norbert Lebenthal
Ranch Hand

Joined: Sep 23, 2010
Posts: 74
thanks again roel

sorry for the delay, but my 2nd child is born in between, so...

well, happy to read you couldn't reproduce the issue.

On my side, it did happen again with the joined mock file:

startingThread thread main
31 janv. 2011 11:06:37 test.log.LogExample run
INFO: about to disable the log
DatabaseBrowseAction outcome thread AWT-EventQueue-0
31 janv. 2011 11:07:14 test.log.LogExample$1 actionPerformed
INFO: file selected /home/zedros/Bureau/mock.db
closeButton ActionPerformed thread AWT-EventQueue-0


The exact workflow was the following:
- launching the app
- click on the browse button
- selection of the home button then click on desktop
- selection of the joined file
- click on the close button

btw, it only happens when I use the .db filter to choose a .db file. With the other filter it doesn't happen.

I'm a on ubuntu 9.10 (more precisely 2.6.31-22-generic #70-Ubuntu SMP Wed Dec 1 23:51:13 UTC 2010 i686 GNU/Linux), using this java:
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.4) (6b20-1.9.4-0ubuntu1~9.10.1)
OpenJDK Server VM (build 19.0-b09, mixed mode)

overall, it feels like a JVM/logging bug to me...
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5514
    
  13

Congratulations with your 2nd mini java developer

Could not reproduce your issue on a winXP with Java 1.6.0_17
Norbert Lebenthal
Ranch Hand

Joined: Sep 23, 2010
Posts: 74
Thanks for the congratulation! I leave my children future up to them... but then I won't be able to spare them totally from IT, that's for sure ;)

Regarding this logging issue, I'm quite annoyed... I guess I'll let the code as it is, I don't want to change it a lot (since it is in a shippable state)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Properly shutting off logging