是否有用于在 Java 中设置默认日志级别的命令行选项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2160471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 19:45:53  来源:igfitidea点击:

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

javalogging

提问by Ben McCann

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?

显然这行不通,但你明白了。有这样的吗?还是我被迫创建一个属性文件?

采纳答案by Laurent K

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.

但我认为您正在寻找一个更“内置”和自动处理的属性,对吗?AFAIK,它不存在,但也许我错了。

回答by Alon

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