aspose file tools*
The moose likes Java in General and the fly likes how to suppress java.util.logging messages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to suppress java.util.logging messages" Watch "how to suppress java.util.logging messages" New topic
Author

how to suppress java.util.logging messages

Mike Thon
Greenhorn

Joined: May 12, 2010
Posts: 5

I'm learning how to user java.util.logging. I can log messages to the console but I would like to suppress the messages when a user runs my program. Is there a way to set a different default logging level for development vs deployment? I can see how to change the log level with logger.setLevel() but if I use this then I have to change code in each class with a logger when I want to deploy my project. Obviously not the way to do it.
Thanks
Andrey Kozhanov
Ranch Hand

Joined: Mar 12, 2010
Posts: 79
Why not to read log level from command line or some configuration file?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Too difficult a question for "beginning Java", so I shall move it.
Mike Thon
Greenhorn

Joined: May 12, 2010
Posts: 5

Andrey Kozhanov wrote:Why not to read log level from command line or some configuration file?


Of course, why didn't I think of that? The other problem is that the docs recommend creating a separate logger for each class. Then I would need to ensure that the log level is set for each class. Seems like a lot of lines of code to write to set up logging and control the level of verbosity, so it seem like I'm doing it wrong.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

Mike Thon wrote:The other problem is that the docs recommend creating a separate logger for each class. Then I would need to ensure that the log level is set for each class. Seems like a lot of lines of code to write to set up logging and control the level of verbosity, so it seem like I'm doing it wrong.

The loggers are hierachical (based on a dot-separated convention) and inherit their levels from their parent if not set specifically. So you only need to set the level at the top of the tree.

For example, if you're naming the loggers after your classes, and all your classes are below com.myapp, you can create a logger for "com.myapp" and set the level on that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to suppress java.util.logging messages
 
Similar Threads
commons logging level
How to supress Runtime Exceptions
Jboss Configuration Property
How to suppress logging messages from stderr?
java.util.logging configuration