Commons登录使用java.util.logging [英] Commons logging to use java.util.logging
问题描述
我正在尝试使用commons日志记录并希望使用java.util.logging作为底层机制。
I am trying to use commons logging and want to use java.util.logging as underlying mechanism.
LogTest.java
import org.apache.commons.logging.*;
public class LogTest {
public static void main(String args[]) {
System.setProperty("java.util.logging.config.file","log.properties");
Log logger = LogFactory.getLog(LogTest.class);
logger.trace("trace msg");
}
}
我有src / main / resources / log.properties (我正在使用maven项目)
I have src/main/resources/log.properties ( I am using maven project )
handlers=java.util.logging.ConsoleHandler
# Default global logging level.
# Loggers and Handlers may override this level
.level=ALL
I我无法看到任何输出。
请告诉我如何以编程方式设置log.properties以利用java日志记录。
I am not able to see any output. Please tell me how to programatically set the log.properties to leverage java logging.
推荐答案
您需要指定一个实现Log接口的记录器。在这种情况下, Jdk14Logger 。
You need to specify a logger that implements the Log interface. In this case, the Jdk14Logger.
查看如何使用'Apache Commons Logging'和'Java SE Logging'?获取更多详细信息。
Check out How to use 'Apache Commons Logging' with 'Java SE Logging'? for more details.
除了链接:
在应用程序的类路径中放入
commons-logging.properties
文件。
此文件的内容应如下所示:
org.apache.commons.logging.Log = org.apache.commons.logging.impl.Jdk14Logger
设置此属性指示Commons-Logging使用JDK Logger
(即Java SE Logger)作为Log实现。
Put "
commons-logging.properties
" file in your application's classpath. The contents of this file should look like:org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger
Setting this property instructs Commons-Logging to use JDK Logger (i.e. Java SE Logger) as the Log implementation.
然后在您的类路径中放入 log-config.properties
并进行相应的配置。
Then put log-config.properties
in your classpath and configure accordingly.
如果您决定将来改变impls,更多记录器是开箱即用。
If you decide to change impls in the future, more loggers are available out of the box.
这篇关于Commons登录使用java.util.logging的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!