对WAR项目忽略Wildfly 10每部署日志记录log4j.xml

时间:2016-07-13 17:04:52

标签: java maven logging wildfly wildfly-10

我在使Wildfly 10应用程序中的部署日志记录正常运行时遇到问题。

我把log4j.xml文件放在WEB-INF / classes:

<log4j:configuration debug="true"
xmlns:log4j='http://jakarta.apache.org/log4j/'>

<appender name="fileAppender" class="org.apache.log4j.rolling.RollingFileAppender">
    <param name="MaxFileSize" value="300MB" />
    <param name="append" value="true" />
    <param name="Encoding" value="UTF-8" />
    <param name="file" value="${jboss.server.log.dir}/rtc-notify.log" />

    <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
        <!-- Archive file to roll to @ midnight (yyyy-MM-dd) with compression -->
        <param name="FileNamePattern"
            value="${jboss.server.log.dir}/rtc-notify.%d{yyyy-MM-dd}.log.gz" />
    </rollingPolicy>

    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] [%t] %m%n" />
    </layout>
</appender>
<root>
    <level value="DEBUG" />
    <appender-ref ref="fileAppender" />
</root>
</log4j:configuration>

但是永远不会创建文件,也不会在任何地方出现任何日志,即使在主server.log文件中也是如此。

我没有更改add-logging-api-dependenciesuse-deployment-logging-config,所以Wildfly应该接受这个。

也许它与pom.xml中的依赖项有关?

<?xml version="1.0" encoding="UTF-8"?>
<!-- JBoss, Home of Professional Open Source Copyright 2013, Red Hat, Inc. 
  and/or its affiliates, and individual contributors by the @authors tag. See 
  the copyright.txt in the distribution for a full listing of individual contributors. 
  Licensed under the Apache License, Version 2.0 (the "License"); you may not 
  use this file except in compliance with the License. You may obtain a copy 
  of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required 
  by applicable law or agreed to in writing, software distributed under the 
  License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 
  OF ANY KIND, either express or implied. See the License for the specific 
  language governing permissions and limitations under the License. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.myapp.notify</groupId>
  <artifactId>myapp-notify</artifactId>
  <version>1.0.0.Final</version>
  <packaging>war</packaging>
  <name>WildFly Quickstarts: myapp-notify</name>
  <description>A starter Java EE 7 webapp project for use on JBoss WildFly / WildFly, generated from the jboss-javaee6-webapp archetype</description>

  <url>http://wildfly.org</url>
  <licenses>
    <license>
      <name>Apache License, Version 2.0</name>
      <distribution>repo</distribution>
      <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
    </license>
  </licenses>

  <properties>
    <!-- Explicitly declaring the source encoding eliminates the following 
      message: -->
    <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered 
      resources, i.e. build is platform dependent! -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <!-- JBoss dependency versions -->
    <version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>

    <!-- Define the version of the JBoss BOMs we want to import to specify 
      tested stacks. -->
    <version.jboss.bom>8.2.0.Final</version.jboss.bom>

    <!-- other plugin versions -->
    <version.compiler.plugin>3.1</version.compiler.plugin>
    <version.surefire.plugin>2.16</version.surefire.plugin>
    <version.war.plugin>2.5</version.war.plugin>

    <!-- maven-compiler-plugin -->
    <maven.compiler.target>1.7</maven.compiler.target>
    <maven.compiler.source>1.7</maven.compiler.source>
  </properties>


  <dependencyManagement>
    <dependencies>

      <dependency>
        <groupId>org.wildfly</groupId>
        <artifactId>wildfly-spec-api</artifactId>
        <version>8.2.0.Final</version>
      </dependency>

      <dependency>
        <groupId>org.wildfly.bom</groupId>
        <artifactId>jboss-javaee-7.0-with-hibernate</artifactId>
        <version>${version.jboss.bom}</version>
        <type>pom</type>
        <scope>import</scope>
        <exclusions>
          <exclusion>  <!-- declare the exclusion here -->
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-search</artifactId>
          </exclusion>
          <exclusion>  <!-- declare the exclusion here -->
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-search-analyzers</artifactId>
          </exclusion>
          <exclusion>  <!-- declare the exclusion here -->
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-search-engine</artifactId>
          </exclusion>
          <exclusion>  <!-- declare the exclusion here -->
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-search-orm</artifactId>
          </exclusion>
          <exclusion>  <!-- declare the exclusion here -->
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-search-infinispan</artifactId>
          </exclusion>
        </exclusions>
      </dependency>

      <!-- https://mvnrepository.com/artifact/log4j/log4j -->
      <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
        <scope>provided</scope>
      </dependency>


      <!-- <dependency> -->
      <!-- <groupId>org.slf4j</groupId> -->
      <!-- <artifactId>slf4j-log4j12</artifactId> -->
      <!-- <version>1.7.10</version> -->
      <!-- </dependency> -->

      <!-- <dependency> -->
      <!-- <groupId>org.slf4j</groupId> -->
      <!-- <artifactId>slf4j-api</artifactId> -->
      <!-- <version>1.7.10</version> -->
      <!-- </dependency> -->

      <!-- <dependency> -->
      <!-- <groupId>org.slf4j</groupId> -->
      <!-- <artifactId>slf4j-simple</artifactId> -->
      <!-- <version>1.7.10</version> -->
      <!-- </dependency> -->

    </dependencies>
  </dependencyManagement>

  <dependencies>

    <dependency>
      <groupId>org.hibernate.javax.persistence</groupId>
      <artifactId>hibernate-jpa-2.1-api</artifactId>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-search-backend-jms</artifactId>
      <version>5.2.0.Final</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-search-orm</artifactId>
      <version>5.2.0.Final</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-search-engine</artifactId>
      <version>5.2.0.Final</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-search-infinispan</artifactId>
      <version>5.2.0.Final</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.infinispan</groupId>
      <artifactId>infinispan-core</artifactId>
      <version>7.0.3.Final</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <scope>provided</scope>
    </dependency>


    <dependency>
      <groupId>org.jboss.spec.javax.jms</groupId>
      <artifactId>jboss-jms-api_2.0_spec</artifactId>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-core-asl</artifactId>
      <version>1.9.13</version>
    </dependency>

    <dependency>
      <groupId>org.jboss.spec.javax.json</groupId>
      <artifactId>jboss-json-api_1.0_spec</artifactId>
    </dependency>

    <dependency>
      <groupId>org.apache.tomcat</groupId>
      <artifactId>tomcat-catalina</artifactId>
      <version>8.0.12</version>
    </dependency>

    <dependency>
      <groupId>org.jboss.spec.javax.websocket</groupId>
      <artifactId>jboss-websocket-api_1.0_spec</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- First declare the APIs we depend on and need for compilation. All 
      of them are provided by JBoss WildFly -->

    <!-- Import the CDI API, we use provided scope as the API is included in 
      JBoss WildFly -->
    <dependency>
      <groupId>javax.enterprise</groupId>
      <artifactId>cdi-api</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- Import the Common Annotations API (JSR-250), we use provided scope 
      as the API is included in JBoss WildFly -->
    <dependency>
      <groupId>org.jboss.spec.javax.annotation</groupId>
      <artifactId>jboss-annotations-api_1.2_spec</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- Import the JAX-RS API, we use provided scope as the API is included 
      in JBoss WildFly -->
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>jaxrs-api</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- Import the EJB API, we use provided scope as the API is included in 
      JBoss WildFly -->
    <dependency>
      <groupId>org.jboss.spec.javax.ejb</groupId>
      <artifactId>jboss-ejb-api_3.2_spec</artifactId>
      <scope>provided</scope>
    </dependency>

  </dependencies>

  <build>
    <!-- Maven will append the version to the finalName (which is the name 
      given to the generated war, and hence the context root) -->
    <finalName>${project.artifactId}</finalName>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>${version.war.plugin}</version>
        <configuration>
          <!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
      <!-- The WildFly plugin deploys your war to a local WildFly container -->
      <!-- To use, run: mvn package wildfly:deploy -->
      <plugin>
        <groupId>org.wildfly.plugins</groupId>
        <artifactId>wildfly-maven-plugin</artifactId>
        <version>${version.wildfly.maven.plugin}</version>
        <configuration>
          <filename>${project.artifactId}.war</filename>
          <skip>false</skip>
          <home>${wildfly-home}</home>
          <hostname>${wildfly-hostname}</hostname>
          <port>${wildfly-port}</port>
          <username>${wildfly-username}</username>
          <password>${wildfly-password}</password>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

我正在使用8.2.0.Final用于jboss-javaee-7.0-with-hibernate,因为BOM没有为Wildfly 10做好准备。我应该手动更改所有依赖项而不依赖于bom吗?

1 个答案:

答案 0 :(得分:0)

问题在于我试图使用的FileAppender。具有每日压缩功能的RollingFileAppender在基本的log4j包中不可用。 apache-log4j-extras软件包是必需的,但Wildfly 10不附带。在我们之前使用Wildfly 8的设置中,我们手动添加了这个模块,但在迁移过程中已经忘记了它。