Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to suppress java.util.logging messages

 
Mike Thon
Greenhorn
Posts: 6
Linux Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not to read log level from command line or some configuration file?
 
Campbell Ritchie
Sheriff
Pie
Posts: 50242
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too difficult a question for "beginning Java", so I shall move it.
 
Mike Thon
Greenhorn
Posts: 6
Linux Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic