Log4j不会使用websphere 8.5在日志文件中记录异常

时间:2014-09-11 12:51:59

标签: log4j websphere

我在我的应用程序中使用log4j.xml。我的log4j文件位于我的WEB-INF文件夹中。当我在glassfish和tomcat中部署相同的应用程序时,记录器也会在文件和控制台中登录,它还会创建滚动文件appender。问题是当我在WEB Sphere 8.5中部署相同的应用程序时,logger不记录异常或错误,它只记录调试/信息消息。它还每天创建滚动文件。我正在为我的应用程序使用spring集成框架。

我的log4j.xml

    <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!-- <!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd"> -->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <!-- Appenders -->
    <appender name="console" class="org.apache.log4j.ConsoleAppender">
        <param name="Target" value="System.out" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n" />
        </layout>
    </appender>
 <appender name="RollingAppender" class="org.apache.log4j.DailyRollingFileAppender">
       <param name="File" value="my.log"/>
       <param name="MaxFileSize" value="20MB" />
        <param name="MaxBackupIndex" value="40" />
       <param name="DatePattern" value="'.'yyyy-MM-dd" />
       <layout class="org.apache.log4j.PatternLayout">
          <param name="ConversionPattern" value="[%p] %d %c %M - %m%n"/>          
       </layout>
    </appender>
    <!-- Loggers -->
    <logger name="org.springframework">
        <level value="ALL" />
    </logger>
    <logger name="org.springframework.integration">
        <level value="ALL" />
    </logger>

    <logger name="com.mycompany.myapplication">
        <level value="debug" />
    </logger>

    <!-- Root Logger -->
    <root>
        <priority value="ALL" />
        <appender-ref ref="console" />
        <priority value="ALL"/>
        <appender-ref ref="RollingAppender" />
    </root>

</log4j:configuration>

my.log

 [INFO] ****-**-** 09:57:59,750 com.mycompany.myapplication.h.GNH icn - ******
[INFO] ****-**-** 09:57:59,751 com.mycompany.myapplication.h.GNH number - number  ****
[INFO] ****-**-** 09:57:59,751 com.mycompany.myapplication.h.GNH number - 010114
[INFO] ****-**-** 09:57:59,751 com.mycompany.myapplication.h.GNH number - 2014
[INFO] ****-**-** 09:57:59,751 com.mycompany.myapplication.h.GNH number - number -->010114
[INFO] ****-**-** 09:57:59,752 com.mycompany.myapplication.h.GNH **** - number 010114
[INFO] ****-**-** 09:57:59,755 com.mycompany.myapplication.h.GNH **** - ********46
[INFO] ****-**-** 09:57:59,755 com.mycompany.myapplication.h.GNH **** - number *****46
[INFO] ****-**-** 09:57:59,755 com.mycompany.myapplication.h.GNH **** - number ******
[DEBUG] ****-**-** 09:57:59,758 com.mchange.v2.resourcepool.BasicResourcePool awaitAcquire - awaitAvailable(): [unknown]
[DEBUG] ****-**-** 09:57:59,758 com.mchange.v2.resourcepool.BasicResourcePool trace - trace com.mchange.v2.resourcepool.BasicResourcePool@67839a5c [managed: 0, unused: 0, excluded: 0]
[WARN] ****-**-** 09:58:13,287 com.mchange.v2.async.ThreadPoolAsynchronousRunner run - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@bcbb4afc -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
[WARN] ****-**-** 09:58:13,331 com.mchange.v2.async.ThreadPoolAsynchronousRunner run - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@bcbb4afc -- APPARENT DEADLOCK!!! Complete Status: [num_managed_threads: 3, num_active: 0; activeTasks: ; pendingTasks: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@9a3e206d]
[INFO] ****-**-** 10:12:14,846 com.mycompany.myapplication.h.GNH icn - Incremented by *******
[INFO] ****-**-** 10:12:14,846 com.mycompany.myapplication.h.GNH number - number****
[INFO] ****-**-** 10:12:14,847 com.mycompany.myapplication.h.GNH number - number -->010114
[INFO] ****-**-** 10:12:14,847 com.mycompany.myapplication.h.GNH number - number ****
[INFO] ****-**-** 10:12:14,847 com.mycompany.myapplication.h.GNH number - number -->010114
[INFO] ****-**-** 10:12:14,847 com.mycompany.myapplication.h.GNH **** - number 010114
[INFO] ****-**-** 10:12:14,851 com.mycompany.myapplication.h.GNH **** - ********47
[INFO] ****-**-** 10:12:14,851 com.mycompany.myapplication.h.GNH **** - number *****47
[INFO] ****-**-** 10:12:14,851 com.mycompany.myapplication.h.GNH **** - number number****
[INFO] ****-**-** 10:26:11,437 com.mycompany.myapplication.h.GNH icn - Incremented Value*****
[INFO] ****-**-** 10:26:11,437 com.mycompany.myapplication.h.GNH number - number Mon ***
[INFO] ****-**-** 10:26:11,437 com.mycompany.myapplication.h.GNH number - number -->010114
[INFO] ****-**-** 10:26:11,438 com.mycompany.myapplication.h.GNH number - number Mon ****
[INFO] ****-**-** 10:26:11,438 com.mycompany.myapplication.h.GNH number - number -->010114
[INFO] ****-**-** 10:26:11,438 com.mycompany.myapplication.h.GNH **** - number 010114
[INFO] ****-**-** 10:26:11,443 com.mycompany.myapplication.h.GNH **** - ********48
[INFO] ****-**-** 10:26:11,444 com.mycompany.myapplication.h.GNH **** - number *****48
[INFO] ****-**-** 10:26:11,444 com.mycompany.myapplication.h.GNH **** - number number***** 048

我按照以下链接但问题仍然相同: http://www-01.ibm.com/support/docview.wss?uid=swg27004610&aid=1 请为上述问题提供意见。


更新:

请在下面找到我的web.xml:

<context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>/WEB-INF/log4j.xml</param-value>
    </context-param>
    <context-param>
        <param-name>log4jExposeWebAppRoot</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>log4jRefreshInterval</param-name>

        <param-value>1000</param-value>
    </context-param>

    <!-- Log4jConfigListener config listener -->
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

1 个答案:

答案 0 :(得分:0)

有同样的问题。
Websphere无法找到你的xml只是因为它在你的战争中应该如此。
您需要通过在代码中明确指定名称和位置来加载文件,或者将xml放在文件夹中并将此文件夹添加到服务器配置中的classpath。 我们使用一个完全不同的文件夹来保存/ projects /等配置文件,并将文件加载到静态块中。