有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java位置log4j。gradle生成系统中的属性文件

我能够使用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。“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

有人能帮忙吗

谢谢,, 艾哈迈德


共 (1) 个答案

  1. # 1 楼答案

    从配置documentation

    If a test file cannot be located the properties ConfigurationFactory will look for log4j2.properties on the classpath.

    因此,只需将配置文件重命名为log4j2.properties