Log4J配置不在JBoss AS7中显示Spring Transaction和其他日志 [英] Log4J configuration not displaying Spring Transaction and other logs in JBoss AS7

查看:123
本文介绍了Log4J配置不在JBoss AS7中显示Spring Transaction和其他日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的log4j.properties:

Following is my log4j.properties:

log4j.rootLogger=ALL, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %p [%c] - %m%n


log4j.logger.org.springframework=ALL
log4j.logger.app.dev.ems=ALL
log4j.logger.org.springframework.transaction=ALL

我在web.xml中提到了 log4jConfigLocation

I have mentioned the log4jConfigLocation in the web.xml:

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/resources/log4j.properties</param-value>
</context-param>

还定义了它的监听类:

<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

但我无法在控制台中看到Spring Transaction日志。同样来自一个类: app.dev.ems.web.wicket.page.home.HomePage 当我这样做时:

But I am unable to see the Spring Transaction log in console. Also from a class: app.dev.ems.web.wicket.page.home.HomePage when I am doing:

Logger logger = LoggerFactory.getLogger(getClass());

public HomePage() {     
    logger.debug("<<<<<<<<<<<<<<<<<<<JYM>>>>>>>>>>>>>>>>>>");//if logger.info is used then it is showing.       
}

这也没有显示该日志。我在Wicket应用程序中并设置了:

This is also not displaying that log. I am in Wicket Application and I have set:

<init-param>
    <param-name>configuration</param-name>
    <param-value>DEVELOPMENT</param-value>
</init-param>

定义WicketServlet时。

While defining the WicketServlet.

I我无法找到问题。任何信息对我都非常有用。

I am unable to find the problem. Any information will be very helpful to me.

注意:如果你想让我发布applicationContext.xml,我可以这样做。交易是注释驱动的。

NB: If you want me to post the applicationContext.xml I can do that. Th Transaction is Annotation driven.

我有log4j-1.2.14,slf4j-api-1.6.1,slf4j- log4j12-1.4.2补充说。我正在使用JBoss AS-7.1.0-Final。

I have log4j-1.2.14, slf4j-api-1.6.1, slf4j-log4j12-1.4.2 added. And I am using JBoss AS-7.1.0-Final.

在其他SO线程中,我看到这是JBoss的问题,并且根据我给出的指令,我有在WEB-INF中添加了jboss-deployment-structure.xml(也尝试使用META-INF):

In other SO thread I saw that this is problem with JBoss, and as per the instruction given there I have added jboss-deployment-structure.xml in WEB-INF(also tried with META-INF):

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <module name="org.apache.log4j" />
        </exclusions>
    </deployment>
</jboss-deployment-structure> 

并在applicationContext.xml中定义了一个bean,它将加载log4j.properties:

And defined a bean in applicationContext.xml which will load the log4j.properties:

<bean id="log4jInitializer" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetClass" value="org.springframework.util.Log4jConfigurer" />
    <property name="targetMethod" value="initLogging" />
    <property name="arguments">
        <list>
            <value>classpath:/app/dev/ems/web/log4j.properties</value>
        </list>
    </property>
</bean>

但不幸的是它没有用。

推荐答案

使用 jboss-deployment-structure.xml 排除应该有效。如果不是,则可能是配置文件的位置。我不熟悉Spring,所以可能添加< context-param /> 是指定日志配置位置的典型方法。

Using the jboss-deployment-structure.xml exclusion should be working. If it's not, it could be the location of your configuration file. I'm not familiar with Spring so maybe adding the <context-param/> is a typical way to specify the location of the log configuration.

您可能想尝试将 log4j.properties 移动到 WEB-INF / classes META-INF 存档目录。您还要确保在部署中包含log4j库。

You might want to try to move your log4j.properties to the to the WEB-INF/classes or META-INF directory of your archive. Also you make sure you're including the log4j library in your deployment.

FWIW jboss-deployment-structure.xml 。它还没有发布,但是它位于上游源代码中。

FWIW the jboss-deployment-structure.xml will no longer be needed for logging configurations. It's not in a release yet, but it is in the upstream source.

因为看起来你正在寻找一种打开调试的方法,你需要做两件事。您需要设置一个处理程序以允许调试消息通过。您还需要设置一个记录器,如果不是所有消息都至少允许调试。

Since it seems you're looking for a way to turn on debugging you need to do two things. You need to set a handler to allow debug messages to come through. You also need to setup a logger that will allow at least debug if not all messages to come through.

例如,在您的情况下,您将创建一个这样的记录器。 / p>

For example in your case you would create a logger like so.

<logger category="app.dev.ems.web.wicket" />

这将创建一个记录器,将记录所有级别。现在创建一个处理程序,或者更改以前定义的处理程序以接受调试消息。

That will create a logger that will log at all levels. Now create a handler, or change a previously defined handler to accept debug messages.

另一个例子是为特定的记录器创建一个文件处理程序,将你的日志消息打印成一个文件。

Another example would be creating a file handler for your specific logger that will print your log message into a file.

<file-handler name="myFileHandler>
    <level name="DEBUG"/>
    <file relative-to="jboss.server.log.dir" path="my-log.log"/>
</file-handler>

现在创建你的记录器并为其分配处理程序。

Now create your logger and assign the handler to it.

<logger category="app.dev.ems.web.wicket">
    <handlers>
        <handler name="myFileHandler/>
    </handlers>
<logger>

现在所有日志消息都通过一个类别为 app的记录器传递。除了连接到root-logger的处理程序之外,dev.ems.web.wicket。* 将打印到该文件。如果您不想在默认的 server.log 中或在控制台上看到这些,您可以添加 use-parent-handler =false记录器的属性。

Now all log messages passed through a logger that has a category of app.dev.ems.web.wicket.* will print to that file in addition to the handlers attached to the root-logger. If you don't want to see these in the default server.log or on the console you can add the use-parent-handler="false" attribute to the logger.

这篇关于Log4J配置不在JBoss AS7中显示Spring Transaction和其他日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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