2016-07-13 15 views
0

Ich habe Probleme, die Protokollierung pro Deployment in meiner Wildfly 10-Anwendung korrekt auszuführen.Wildfly 10 Protokollierung pro Deployment log4j.xml ignoriert für WAR-Projekt

habe ich die Datei log4j.xml in 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> 

Aber die Datei nie erstellt und keine Protokolle erscheinen überall, auch in der Haupt server.log-Datei.

Ich habe weder die add-logging-api-dependencies noch die use-deployment-logging-config geändert, also sollte Wildfly dies akzeptieren.

Vielleicht hat es etwas mit den Abhängigkeiten in pom.xml zu tun?

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

Ich verwende 8.2.0.Final für Jboss-JavaEE-7.0-mit-überwintern als die BOM nicht für Wildfly vorbereitet 10. Soll ich die Abhängigkeiten alle hier manuell und nicht auf die bom verlassen ändern ?

Antwort

0

Das Problem war mit dem FileAppender, den ich verwenden wollte. Der RollingFileAppender mit täglicher Komprimierung ist im Basispaket log4j nicht verfügbar. Das Paket apache-log4j-extras ist erforderlich, aber es ist nicht mit Wildfly 10 enthalten. Bei unserem vorherigen Setup mit Wildfly 8 haben wir dieses Modul manuell hinzugefügt, es wurde jedoch während der Migration vergessen.

+0

Sie ist in log4j verfügbar, nur nicht im 'org.apache.log4j.rolling' Paket. Es funktioniert, wenn Sie 'org.apache.log4j.RollingFileAppender' verwenden. FWIW Ich habe eine JIRA eingereicht, um den Fehler zu beheben, die Fehlermeldungen nicht von log4j zu drucken https://issues.jboss.org/browse/WFCORE-1656 –

+0

Ich war mir dessen nicht bewusst. Danke für den Hinweis zur grundlegenden log4j-Bibliothek. Es ist besser, wenn wir die Verwendung zusätzlicher Module vermeiden können. Und ja, eine Art Fehlermeldung wäre extrem nützlich. – PawelPredki

+0

Soweit ich jedoch in der Dokumentation sehen kann, ist die TimeBasedRollingPolicy-Klasse im Basispaket log4j nicht verfügbar und DailyRollingFileAppender soll einige Probleme haben und daher wird die Verwendung von Extras ohnehin empfohlen. In diesem Fall denke ich, dass wir bei der Verwendung von Extras bleiben werden, da es bereits konfiguriert ist und funktioniert. – PawelPredki