java - Log4j 在随机时间/使用后停止工作

标签 java eclipse logging log4j wildfly

我正在努力处理此消息:

15:34:47,323 INFO [stdout] (Finalizer) log4j: Finalizing appender named [consoleAppender].

在我的项目上工作大约一小时后,愉快地在 Eclipse 控制台中查看我的应用程序日志,出现此消息并且控制台保持为空。

我找不到原因:该项目运行在Wildfly9,jdk1.8上。我的(最小)log4j.xml 文件与另一个项目相同!

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

    <appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
        <param name="target" value="System.out" />
        <param name="threshold" value="info" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
        </layout>
    </appender>

    <logger name="org.hibernate">
        <level value="info" />
    </logger>

    <root>
        <appender-ref ref="consoleAppender" />
    </root>

</log4j:configuration>

我想有一些限制,在某个点“切割”我的日志。我的问题是:在哪里?

编辑

这是我的 pom.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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>it.xxx</groupId>
    <artifactId>yyy</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>yyy.com</name>
    <description>yyy.com</description>
    <url>http://www.yyy.com</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>
        <version.jboss.bom>10.0.0.CR4</version.jboss.bom>
        <version.javax.servlet.jstl>1.2</version.javax.servlet.jstl>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>        
        <version.compiler.plugin>2.3.1</version.compiler.plugin>
        <version.surefire.plugin>2.4.3</version.surefire.plugin>
        <version.war.plugin>2.6</version.war.plugin>        
        <internal.repo>trew</internal.repo>
    </properties>

    <repositories>
        <repository>
            <id>prime-repo</id>
            <name>Prime Repo</name>
            <url>http://repository.primefaces.org</url>
        </repository>
        <repository>
            <id>xxx-maven-repo</id>
            <name>artifactory xxx</name>            
            <url>http://x.x.x.x:8081/artifactory/xxx-maven-repo/</url>
        </repository>
    </repositories>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.wildfly.bom</groupId>
                <artifactId>wildfly-javaee7-with-tools</artifactId>
                <version>${version.jboss.bom}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>

        <dependency>
            <groupId>xxx</groupId>
            <artifactId>xxx-commons</artifactId>
            <version>1.4.0</version>
        </dependency>

        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.spec.javax.annotation</groupId>
            <artifactId>jboss-annotations-api_1.2_spec</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.spec.javax.servlet</groupId>
            <artifactId>jboss-servlet-api_3.1_spec</artifactId>
            <scope>provided</scope>
        </dependency>

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

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

        <dependency>
            <groupId>org.jboss.spec.javax.ejb</groupId>
            <artifactId>jboss-ejb-api_3.2_spec</artifactId>
            <scope>provided</scope>
        </dependency>

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

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>${version.javax.servlet.jstl}</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

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

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.5</version>
        </dependency>

        <dependency>
            <groupId>javax.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.1</version>
        </dependency>

        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>5.3</version>
        </dependency>
        <dependency>
            <groupId>org.primefaces.themes</groupId>
            <artifactId>redmond</artifactId>
            <version>1.0.10</version>
        </dependency>
        <dependency>
            <groupId>org.primefaces.themes</groupId>
            <artifactId>bootstrap</artifactId>
            <version>1.0.10</version>
        </dependency>

        <dependency>
            <groupId>com.maxmind.geoip</groupId>
            <artifactId>geoip-api</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.jglue.cdi-unit</groupId>
            <artifactId>cdi-unit</artifactId>
            <version>3.1.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>javax.mail</artifactId>
            <version>1.5.3</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>

        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.2</version>
        </dependency>

    </dependencies>

    <build>        
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>${version.war.plugin}</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>            
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>${version.wildfly.maven.plugin}</version>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>            
            <id>default</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>${version.surefire.plugin}</version>
                        <configuration>
                            <skip>true</skip>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

    </profiles>
</project>

最佳答案

在您的 pom.xml 中,有 slf4j-apislf4j-log4j12。部署到 Wildfly 时,您不需要它们,因为它隐式添加了日志记录依赖项。您可以将 slf4j-api 设置为提供或排除 Wildfly 的日志记录库,如链接问题中所述。您还可以使用 add-logging-api-dependencies 禁用自动添加 Wildfly 的日志记录库,如 in Wildfly's documentation 中所述。

关于java - Log4j 在随机时间/使用后停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36202969/

相关文章:

java - 从 Eclipse 插件编辑 web.xml 的 API?

android - dex 加载程序无法执行 dex : method ID not in [0, 0xffff]:65536

java - 如何在 IntelliJ IDEA 中查看本地运行的 AppEngine 应用程序的调试日志?

java - "Passing arguments"通过 ThreadLocal 好吗?

java - RoundRect 不适合 JFrame

java - 让继承类实现父类(super class)的方法

java - 当用户将对象拖动到边界附近时滚动列表

java - 从 Eclipse 推送到 github 时项目丢失

python - 写入并发日志文件

Spring:不同ApplicationContext的不同日志记录行为