java 如何使 logging.properties 和 commons-logging.properties 属性文件工作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4961039/
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-30 08:48:22  来源:igfitidea点击:

How to make logging.properties and commons-logging.properties property files working?

javajava.util.loggingapache-commons-logging

提问by Damian

I have two property files in my default package (I'm using NetBeans):

我的默认包中有两个属性文件(我使用的是 NetBeans):

commons-logging.properties with property:

具有属性的 commons-logging.properties:

org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger

and logging.properties with:

和 logging.properties 具有:

handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=SEVERE

java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

I'm getting INFO level messages in output. What i'm doing wrong? I also haven't found any information about JDK configuration, just example as above.

我在输出中收到 INFO 级别的消息。我在做什么错?我也没有找到任何关于JDK配置的信息,只是上面的例子。

采纳答案by limc

I'm not sure why you have .level=SEVEREappended on the last line, it should just like this:-

我不确定你为什么.level=SEVERE在最后一行附加,它应该是这样的:-

handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=SEVERE
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

回答by Peter Jamieson

How are you calling the java?

你怎么称呼java?

Are you putting -Djava.util.logging.config.file=/logging.properties in your java command?

您是否将 -Djava.util.logging.config.file=/logging.properties 放入您的 java 命令中?

If not, it would ignore your logging.properties and log everything.

如果没有,它将忽略您的 logging.properties 并记录所有内容。

.level=ALL on a line of it's own is used as a global level, e.g. : -

.level=ALL 在它自己的一行上用作全局级别,例如:-

handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=INFO
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
.level=SEVERE
mypackage.level=INFO

would only log INFO messages from mypackage and SEVERE from everything else.

只会记录来自 mypackage 的 INFO 消息和来自其他所有内容的 SEVERE 消息。