代码之家  ›  专栏  ›  技术社区  ›  RedCollarPanda

slf4j+log4j2不写入文件

  •  0
  • RedCollarPanda  · 技术社区  · 7 年前

    很好的一天!我有一个项目,编译成WAR文件,运行在wildfly-10.1.0-FINAL上。不久前,我配置了日志系统,一切都很好。2-3周后,在多次提交之后,一位开发人员注意到日志记录只会进入服务器。wildfly的日志文件,而不是配置的日志。配置的登录为空。同样-日志配置没有更改。可能是什么?

    波姆。xml

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.19</version>
        <scope>${artefact.scope}</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>2.5</version>
        <scope>${artefact.scope}</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.5</version>
        <scope>${artefact.scope}</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.5</version>
        <scope>${artefact.scope}</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-jcl</artifactId>
        <version>2.5</version>
        <scope>${artefact.scope}</scope>
    </dependency>
    

    jboss部署结构。xml

    <deployment>
        <dependencies>
            <module name="org.jboss.ironjacamar.jdbcadapters" />
            <module name="org.postgres" />
        </dependencies>
        <exclusions>
            <module name="org.apache.log4j" />
        </exclusions>
        <exclude-subsystems>
            <subsystem name="logging"/>
        </exclude-subsystems>
    </deployment>
    

    log4j2.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <Configuration status="trace">
        <Properties>
    
    <Property name="log-path">${env:LOG_HOME:-/opt/wildfly-10.1.0.Final/standalone/log/}/admin/</Property>
    </Properties>
    <Appenders>
        <Console name="console-log" target="SYSTEM_OUT">
            <PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %C:%c{1}:%L - %msg%n"/>
        </Console>
    
        <RollingFile name="ADMIN" fileName="${log-path}/admin.log"
                     filePattern="${log-path}/admin-%d{yyyy-MM-dd}.log.gz">
            <PatternLayout>
                <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %C:%c{1}:%L - %msg%n</pattern>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
            </Policies>
        </RollingFile>
    
    </Appenders>
    <Loggers>
    
        <Logger name="my.package" level="INFO" additivity="false" includeLocation="true">
            <appender-ref ref="ADMIN" level="INFO"/>
            <appender-ref ref="console-log" level="DEBUG"/>
        </Logger>
    
    </Loggers>
    

    PS.在我的服务器中。我能看到这个-

    15:05:08,007 ERROR [stderr] (ServerService Thread Pool -- 111) SLF4J: Class path contains multiple SLF4J bindings.
    15:05:08,007 ERROR [stderr] (ServerService Thread Pool -- 111) SLF4J: Found binding in [vfs:/content/admin-1.0-SNAPSHOT-dev.war/WEB-INF/lib/slf4j-jdk14-1.7.5.jar/org/slf4j/impl/StaticLoggerBinder.class]
    
    15:05:08,008 ERROR [stderr] (ServerService Thread Pool -- 111) SLF4J: Found binding in [vfs:/content/admin-1.0-SNAPSHOT-dev.war/WEB-INF/lib/log4j-slf4j-impl-2.5.jar/org/slf4j/impl/StaticLoggerBinder.class]
    
    15:05:08,008 ERROR [stderr] (ServerService Thread Pool -- 111) SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
    
    15:05:08,009 ERROR [stderr] (ServerService Thread Pool -- 111) SLF4J: Actual binding is of type [org.slf4j.impl.JDK14LoggerFactory]
    

    事情是这样的-文件已创建,但它是空的。 有什么想法吗?

    非常感谢。

    1 回复  |  直到 7 年前
        1
  •  1
  •   nayakam    7 年前

    您必须解决依赖项之间的冲突。您可以使用mvn依存关系:树来识别依存关系,然后删除或排除它们。

    从服务器日志: StaticLoggerBinder。班 从log4j-slf4j和slf4j-jdk14加载,冲突。所以您可以排除slf4j-jdk14库并尝试。进一步了解 multiple binding

    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
           <artifactId>slf4j-jdk14</artifactId>
        </exclusion>
    </exclusions>