log4j2 not finding my external file when run from intelliJ

已回答

I created a small project that illustrates the issue. The pom, main class and log4j2.yml file are in the following upload:

Upload id: 2022_02_11_64Bse454nthEERtG (files: log4j2.new.yml and 2 more)

When I run LogMe.java from intelliJ with a Run Configuration that has the following Program Arguments:

-Dlog4j.configurationFile=file:/Users/desilets/Documents/conf/log4j2.yml

I get the following error:

ERROR StatusLogger No Log4j 2 configuration file found. 

And the logger.debug() message is not printed.

Yet, if I run it from the command line:

java  -Dlog4j.configurationFile=file:/Users/desilets/Documents/conf/log4j2.yml \
-cp target/log4j2Spike-1.0.jar org.examples.LogMe

All is fine and the expected logger.debug() message is printed:

[DEBUG] 2022-02-11 14:57:40.313 [main] method1 - hi

Why is that?

 

Thx.

评论操作 固定链接

Please share a sample project to reproduce the issue: https://uploads.jetbrains.com.

0
评论操作 固定链接

The zipped project is in this upload:

   Upload ID: 2022_02_11_2iB69eMEfe3q3tNX (file: Log4j2Spike.zip)

The external log2j.yml is in this upload:

   Upload id: 2022_02_11_64Bse454nthEERtG (files: log4j2.new.yml and 2 more)

 

 

0
评论操作 固定链接

Your sample project run configuration is wrong, you put these options into command line arguments field instead of the VM Options field.

 

Another issue is that you may need to use -Dlog4j2.configurationFile instead of -Dlog4j.configurationFile.

0
评论操作 固定链接

I am SO red in the face right now. Sorry and thanks.

0

请先登录再写评论。