Log4j2在WebLogic 12.2.1中不起作用 [英] Log4j2 not working in WebLogic 12.2.1

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

问题描述

我试图在运行于WebLogic 12.2.1的Web服务中添加log4j日志记录,但是以某种方式,日志记录无法正常工作.

I am trying to add log4j logging in my web services running under WebLogic 12.2.1 but somehow the logging is not working.

这是我的WAR文件的WEB-INF \ classes中的log4j2.xml:

This is log4j2.xml in WEB-INF\classes of my WAR file:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
    <Properties>
        <Property name="log-path">E:/MLM/MyDomain/servers/MyAppSrv01/logs</Property>
    </Properties>
    <Appender type="File" name="File" fileName="${log-path}/Services.log" filePattern="${log-path}/Services-%d{yyyy-MM-dd}.log">
        <Layout type="PatternLayout">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </Layout>
    </Appender>
    <Loggers>
        <Root level="INFO">
            <AppenderRef ref="File"/>
        </Root>
    </Loggers>
</Configuration>

这是我的Web服务代码的一部分:

Here is a fragment of my web service codes:

@Path("TestWS")
@Consumes("text/plain")
@Produces("text/plain")
public class TestWS {

    static private Logger logger = LogManager.getLogger();

    public TestWS() {}

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    @Path("webservicemethod1")
    public String webservicemethod1(@Context HttpServletRequest request) {
        logger.error("In webservicemethod1");
        ....
    }

}

在我的WAR文件的WEB-INF \ lib \中,我有:

In WEB-INF\lib\ of my WAR file, I have:

log4j-core-2.5.jar
log4j-api-2.5.jar

我可以使用客户端程序成功调用Web服务.但是我根本看不到日志文件被创建.可能是什么问题?

I can call the web service successfully using a client program. But I don't see the log file getting created at all. What could be the problem?

谢谢.

推荐答案

对于WebLogic 12.1.3及更高版本,我需要将以下内容添加到weblogic.xml文件中,以使log4j正常工作.

For WebLogic 12.1.3 and onward, I've needed to add the following to the weblogic.xml file to get log4j to work.

<wls:container-descriptor>
        <wls:prefer-application-packages>
            <wls:package-name>org.slf4j</wls:package-name>
            <wls:package-name>log4j</wls:package-name>
        </wls:prefer-application-packages>
</wls:container-descriptor>

这篇关于Log4j2在WebLogic 12.2.1中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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