Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

how to suppress java.util.logging messages

 
Greenhorn
Posts: 6
Mac Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not to read log level from command line or some configuration file?
 
Marshal
Posts: 76483
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Too difficult a question for "beginning Java", so I shall move it.
 
Mike Thon
Greenhorn
Posts: 6
Mac Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Uh oh, we're definitely being carded. Here, show him this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic