Quick question,
Looking through these examples which statically assign the logging level of a program
http://www.onjava.com/pub/a/onjava/2002/06/19/log.html?page=2
http://www.vogella.com/articles/Logging/article.html
How can I dynamically set the logging level through an argument when I call my Java application
e.g.
java -jar myprogram.jar FINE
Meaning that instead of this code
logger.setLevel(Level.INFO);
I could have something like
logger.setLevel(args[0]);
When researching the documentation there doesnt appear to be away to set the log level with a string.
http://docs.oracle.com/javase/6/docs/api/java/util/logging/Level.html
You can use builtin method Level.parse(String), which parses a level name string into a Level.
The argument string may consist of either a level name or an integer value.
For example:
You could create a Map of String and Level and refer to that:
logger.setLevel(logmap.get(args[0]));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With