• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Properly shutting off logging

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Norbert Lebenthal
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
reply
    Bookmark Topic Watch Topic
  • New Topic