【问题标题】:slf4j and log4j log messages visible in the console but not appending into logfileslf4j 和 log4j 日志消息在控制台中可见但未附加到日志文件中
【发布时间】:2014-06-16 09:23:06
【问题描述】:

我对 slf4j 和 log4j 有疑问。我可以在控制台中看到日志消息,但这些消息没有附加到文件中

我正在使用以下罐子。

slf4j-log4j12-1.7.5.jar
slf4j-api-1.7.1.jar
log4j-1.2.17.jar

我的 log4j.properties 文件在下面。

    # Root logger option
    log4j.rootLogger=INFO, file

    # Direct log messages to a log file
    log4j.appender.file=org.apache.log4j.RollingFileAppender
    log4j.appender.file.File=C:\\myLogFile.log
    log4j.appender.file.MaxFileSize=1MB
    log4j.appender.file.MaxBackupIndex=1
    log4j.appender.file.layout=org.apache.log4j.PatternLayout
    log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}
 %-5p %c{1}:%L - %m%n

当我运行我的 java 类时,我在控制台中收到以下警告

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/1018835/.m2/repository/ch/qos/logback/logback-classic/1.0.10/logback-classic-1.0.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/1018835/.m2/repository/org/slf4j/slf4j-log4j12/1.7.5/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

【问题讨论】:

    标签: java logging log4j slf4j


    【解决方案1】:

    请检查该位置是否存在文件。

    还要查看您的应用程序是否具有文件的写入权限。

    【讨论】:

    • 也有访问权限?因为我也遇到了同样的问题,并通过给它写访问权限(777)来解决。
    • 这不是问题..我看到了多重绑定的警告
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-14
    • 2015-06-30
    • 2019-02-04
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 2012-07-14
    相关资源
    最近更新 更多