【问题标题】:Location log4j.properties file in gradle build system在 gradle 构建系统中定位 log4j.properties 文件
【发布时间】:2018-11-03 22:53:09
【问题描述】:

我能够使用 log4j2 构建我的简单 Java 应用程序。但是,当我运行该应用程序时,我收到以下错误消息:

$ gradle run
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:run
ERROR StatusLogger No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2

我正在使用 gradle 构建系统。我将文件 - log4j.properties 放在“src/main/resources/”目录中。

$ cat src/main/resources/log4j.properties 

log=/home/aalmehdi/temp/javatut/gradle-demo

# Define the root loogger with appender
log4j.rootlogger=DEBUG, stdout, KPLOGFILE

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d] %p %m (%c)%n

log4j.appender.KPLOGFILE=org.apache.log4j.FileAppender
log4j.appender.KPLOGFILE.File=${log}/kplog.out
log4j.appender.KPLOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.KPLOGFILE.layout.conversionpattern=%m%n

log4j.logger.kplogger=DEBUG, KPLOGFILE

有人可以帮忙吗。

谢谢你, 艾哈迈德。

【问题讨论】:

    标签: java gradle log4j2


    【解决方案1】:

    来自配置documentation:

    如果找不到测试文件,属性 ConfigurationFactory 将在类路径中查找 log4j2.properties。

    所以只需将您的配置文件重命名为log4j2.properties。

    【讨论】:

    • 刚想通,不得不将文件命名为 log4j2.properties。谢谢。
    • 没问题。也学到了一些东西,我们仍在使用 log4j 1。:)
    猜你喜欢
    • 2012-11-27
    • 1970-01-01
    • 1970-01-01
    • 2019-02-11
    • 2014-05-21
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    相关资源
    最近更新 更多