在JBoss 7.1.1下使用应用程序的Log4J配置 [英] Using application's Log4J configuration under JBoss 7.1.1

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

问题描述

我在使用我的XML log4j配置文件中定义的appender进行日志记录时遇到问题。

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

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

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-deployment-structure.xml in subdeployment ignored. jboss-deployment-structure.xml is only parsed for top level deployments.

我甚至尝试从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.

我注意到这种方式异常:

I've noticed that this way the exception:

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
  • b
  • moving my log4j.xml to MyAppEAR.ear/META-INF.
  • removing the unecessary -Dorg.jboss.as.logging.per-deployment=false from standalone.conf.bat
  • removing slot from my jboss-deployment-structure.xml

插槽更多提示?

谢谢

推荐答案

您好RedEagle看到我测试过的以下配置及其工作正常...

Step-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>

Step-2
现在IN my.ear / META -INF /

Step-2 Now 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-4 Here 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配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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