如何配置log4j以使用JULAppender将日志事件发送到java.util.logging? [英] How do I configure log4j to send log events to java.util.logging using JULAppender?

查看:96
本文介绍了如何配置log4j以使用JULAppender将日志事件发送到java.util.logging?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我熟悉java.util.logging(JUL)框架,并且广泛使用它.最近,我开始使用通过log4j进行记录的库.当我启动我的应用程序时,现在在控制台上打印以下内容:

I am familiar with the java.util.logging (JUL) framework, I use it extensively. Recently, I started using a library that does its logging through log4j. When I start my application I now get the following printed on the console:

log4j:WARN No appenders could be found for logger (com.example.thirdparty.Library).
log4j:WARN Please initialize the log4j system properly.

看来log4j对此有解决方案:

It appears that log4j has a solution for this: JULAppender which will send everything logged with log4j to the logging framework that I use.

我找不到任何示例向我展示如何配置log4j以使用此附加程序.

I can't find any examples that show me how to configure log4j to use this appender.

推荐答案

配置log4j的标准方法是在类路径的根目录中创建 log4j.xml .这是为JULAppender配置的文件的内容:

The standard way of configuring log4j is to create log4j.xml in the root of the classpath. Here are contents of that file configured for JULAppender:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    <appender name="jul" class="org.apache.log4j.JulAppender"> 
        <layout class="org.apache.log4j.PatternLayout"> 
            <param name="ConversionPattern" value="%d %-5p %c - %m%n "/> 
        </layout> 
    </appender> 
    <root> 
        <priority value="all" /> 
        <appender-ref ref="jul" /> 
    </root>  
</log4j:configuration>

这篇关于如何配置log4j以使用JULAppender将日志事件发送到java.util.logging?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆