本文介绍了在 JBoss 7.1.1 下使用应用程序的 Log4J 配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 XML log4j 配置文件中定义的附加程序进行日志记录时遇到问题.

I'm am having trouble logging using my appenders defined on my XML log4j configuration file.

我在 EAR 的 META-INF 文件夹中创建了 jboss-deployment-structure.xml,但没有成功.

I created the jboss-deployment-structure.xml on my EAR's META-INF folder with no sucess.

jboss-deployment-structure.xml 结构是:

<jboss-deployment-structure>
<ear-subdeployments-isolated>false</ear-subdeployments-isolated>
    <deployment>
        <exclusions>
            <module name="org.apache.log4j" slot="main"/>
        </exclusions>
    </deployment>
</jboss-deployment-structure>

我什至尝试编辑我的 standalone.conf.bat 文件,添加以下行:

I have even tried to edit my standalone.conf.bat file adding the following line:

set "JAVA_OPTS=%JAVA_OPTS% -Dorg.jboss.as.logging.per-deployment=false"

我的应用部署是这样的:

My application deployment is like this:

-> MyAppEAR.ear
   -> META-INF
      -> MANIFEST.MF
   -> MyAoo.war
      -> META-INF
         -> MANIFEST.MF
         -> jboss-deployment-structure.xml
      -> WEB-INF
         -> web.xml
         -> lib
            -> log4j-1.2.17.jar
            -> ---
         -> classes
            -> log4j.xml
            -> ...

我注意到以下错误:

  • 忽略子部署中的 jboss-deployment-structure.xml.jboss-deployment-structure.xml 仅针对顶级部署进行解析.

我什至尝试从 JBOSS 7.1.0 迁移到 7.1.1

I even tried migrating from JBOSS 7.1.0 to 7.1.1

请帮忙!

谢谢

感谢詹姆斯的回复.

我按照你说的做了,将 jboss-deployment-structure.xml 文件移到了 MyAppEAR.ear/META-INF.

I did what you said and moved the jboss-deployment-structure.xml file to MyAppEAR.ear/META-INF.

我注意到这种异常:

jboss-deployment-structure.xml in subdeployment ignored. jboss-deployment-structure.xml is only parsed for top level deployments.

... 不会发生.我不知道这是否意味着文件被解析...我怎么知道?

... doesn't occur. I don't know if that means that the file was parsed... how can I tell?

尽管有这种新行为,我的 log4j.xml 配置文件仍未加载,并且使用的记录器仍然是 Log4J 的.

Despite of this new behaviour my log4j.xml configuration file still isn't loaded and the logger used still is Log4J's.

我知道这是因为我写信给控制台:

I know this becaused I wrote to the console:

System.out.println(Logger.getRootLogger().getClass().toString())

...得到:

class org.jboss.logmanager.log4j.BridgeLogger

我也试过:

  • 将我的 log4j.xml 移动到 MyAppEAR.ear/META-INF.
  • standalone.conf.bat
  • 中删除不必要的-Dorg.jboss.as.logging.per-deployment=false
  • 从我的 jboss-deployment-structure.xml
  • 中删除 slot

还有什么想法吗?

谢谢

推荐答案

嗨 RedEagle,请参阅我测试过的以下配置并且它工作正常...
第 1 步创建一个新模块为

Hi RedEagle see the following configuration which i have tested and its working fine...
Step-1 Create a new module as

jboss-as-7.1.1.Final/modules/com/company/mylog/main/

jboss-as-7.1.1.Final/modules/com/company/mylog/main/

                          -module.xml
                          -log4j-1.2.14.jar

Content of  module.xml


 <?xml version="1.0" encoding="UTF-8"?>
      <module xmlns="urn:jboss:module:1.0" name="com.company.mylog">
    <resources>
      <resource-root path="log4j-1.2.14.jar"/>
    </resources>
    <dependencies>
      <module name="javax.api"/>
         </dependencies>
      </module>

第 2 步现在在 my.ear/META-INF/

Step-2Now IN my.ear/META-INF/

          -jboss-deployment-structure.xml
          -MANIFEST.MF

jboss-deployment-structure.xml 的内容

content of jboss-deployment-structure.xml

 <jboss-deployment-structure>
              <deployment>

                  <exclusions>
                  <module name="org.apache.log4j" />
                  </exclusions>

              </deployment>


              <sub-deployment name="MyWeb.war">
                    <exclusions>
                    <module name="org.apache.log4j" />
                    </exclusions>
              </sub-deployment>

              <sub-deployment name="MyBeans.jar">
                <exclusions>
                  <module name="org.apache.log4j" />
                </exclusions>
              </sub-deployment>


              </jboss-deployment-structure>

MANIFEST.MF 的内容

Content of MANIFEST.MF

        Manifest-Version: 1.0
        Dependencies: com.company.mylog

第 3 步MyLogger.java 的内容

Step-3 Content of MyLogger.java

public static Logger getLogger(String name) {

    Logger  logger= LogManager.getLogger(name);
    PropertyConfigurator.configure("log4j.properties"); //Path to log4j.properties as many option available in my case for testing i used static path /home/gyani/log4j.properties
    return logger;
}

第 4 步这是 log4j.properties

Step-4Here is log4j.properties

log4j.rootLogger=info,gyani
log4j.appender.gyani=org.apache.log4j.RollingFileAppender
log4j.appender.gyani.File=/home/gyani/myserverlog.log
log4j.appender.gyani.Append=true
log4j.appender.gyani.MaxFileSize=100000KB
log4j.appender.gyani.MaxBackupIndex=10
log4j.appender.gyani.layout=org.apache.log4j.PatternLayout
log4j.appender.gyani.layout.ConversionPattern=[%d{MMM d HH:mm:ss yyyy}] [%-5p] [%c]: %m%n

这篇关于在 JBoss 7.1.1 下使用应用程序的 Log4J 配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 00:50