Log4j2 WebLookup无法解决 [英] Log4j2 WebLookup not getting resolved

查看:467
本文介绍了Log4j2 WebLookup无法解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下log4j2配置

I have the following log4j2 configuration

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="TRACE">
    <Appenders>
        <RollingRandomAccessFile name="SQLTiming" fileName="${web:rootDir}/log/SQLTiming.log"
            filePattern="${web:rootDir}/log/SQLTiming-%d{yyyy-MM-dd}.log">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %logger{2} - %msg%n" />
            <Policies>
                <TimeBasedTriggeringPolicy />
            </Policies>
        </RollingRandomAccessFile>
        <Console name="CONSOLE">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %logger{2} - %msg%n" />
        </Console>
    </Appenders>
    <Loggers>
        <Logger name="jdbc.sqltiming" level="info" additivity="false">
            <AppenderRef ref="SQLTiming" />
        </Logger>
        <Root level="error">
            <AppenderRef ref="CONSOLE" />
        </Root>
    </Loggers>
</Configuration>

当我尝试通过slf4j获取记录器时

When I try to get a logger via slf4j

    protected static Logger logger = LoggerFactory.getLogger(DbConn.class);

Log4j无法创建附加程序.我看过log4j2源,它试图创建文件C:\Program Files\eclipse\${web:rootDir}\log\SQLTiming.log(它做不到),因此看来log4j没有处理查找.

Log4j fails creating an appender. I've looked at the log4j2 source, and it tries to create the file C:\Program Files\eclipse\${web:rootDir}\log\SQLTiming.log (which it fails to do), so it seems that log4j didn't process the lookup.

我正在Tomcat 7.0.4中运行该应用程序,并使用

I am running the application in Tomcat 7.0.4, and using the syntax suggested by http://logging.apache.org/log4j/2.x/manual/lookups.html . I have tried using $${web:rootDir} (with 2 $ marks) which resulted in one of the $-s being removed, but the lookup still didn't succeed. In fact, none of the other lookups succeeded (environment variables for example). Log4j version is 2.0 beta9.

还有其他人看到过类似的东西吗?我想念什么吗?

Has anybody else seen anything similar to this ? Am I missing something ?

推荐答案

该解决方案实际上是按照

The solution was really following the steps described at

http://logging.apache.org/log4j/2. x/manual/webapp.html

(我的应用程序正在servlet 2.5容器中运行)

(My app was running in a servlet 2.5 container)

我只是以某种方式错过了这篇文档(顺便说一句,它很棒)

I just somehow missed this piece of documentation (which is excellent by the way)

这篇关于Log4j2 WebLookup无法解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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