Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a command line option for setting the default log level in Java

Can I do something along the lines of:

-Djava.util.logging.loglevel=FINE

Obviously that doesn't work, but you get the idea. Is there anything like that? Or am I forced to create a properties file?

like image 205
Ben McCann Avatar asked Jan 29 '10 07:01

Ben McCann


People also ask

What is the default logger in Java?

In the Java Logging API, the FileHandler and ConsoleHandler are the two handlers provided by default.

How do you change the log level?

To enable debug logging, run the following command: /subsystem=logging/root-logger=ROOT:change-root-log-level(level=DEBUG) To disable debug logging, run the following command: /subsystem=logging/root-logger=ROOT:change-root-log-level(level=INFO)

What is the default logger level?

The default level for all loggers is Inherit, and the default level for the root logger is Info. Do not turn on Debug or higher logging without direction from technical support. Turning on this excessive logging for high volume module like system, query, or exec can rapidly flood your system and terminate the servers.


2 Answers

You can even pass your log Level as a user defined property.

-DmyProp.logLevel=FINE

In your code:

String logLevel = System.getProperties("myProp.logLevel");

But I have the idea that your are looking for a more "built-in" and automatically handled property, right? AFAIK, it doesn't exist, but maybe I'm wrong.

like image 102
Laurent K Avatar answered Sep 27 '22 17:09

Laurent K


you can configure your code to set the level based on an envrioment variable :

String sLoglevel= System.getenv("LOGLEVEL");  
int ilevel = loglevel.parseInt(sLoglevel);
//set the log level based on retrieved value 
like image 37
Alon Avatar answered Sep 27 '22 17:09

Alon