我可以使用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
有人可以帮忙。
谢谢你, 艾哈迈德。
答案 0 :(得分:3)
来自配置documentation:
如果找不到测试文件,ConfigurationFactory属性将在类路径上查找log4j2.properties。
所以只需将配置文件重命名为log4j2.properties
。