You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "SkyghiS (Jira)" <ji...@apache.org> on 2020/02/06 20:31:00 UTC
[jira] [Created] (LOG4J2-2773) Configuration file loading ignored
on jar-with-dependencies
SkyghiS created LOG4J2-2773:
-------------------------------
Summary: Configuration file loading ignored on jar-with-dependencies
Key: LOG4J2-2773
URL: https://issues.apache.org/jira/browse/LOG4J2-2773
Project: Log4j 2
Issue Type: Bug
Components: Configurators
Affects Versions: 2.13.0, 2.12.1
Environment: {code}
$ java -version
openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.6+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.6+10, mixed mode)
{code}
{code}
$ mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /home/ghislain/app/apache-maven-3.6.3
Java version: 11.0.6, vendor: AdoptOpenJDK, runtime: /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.3.0-29-generic", arch: "amd64", family: "unix"
{code}
{code}
$ lsb_release -d
Description: Ubuntu 19.10
{code}
Reporter: SkyghiS
Attachments: image-2020-02-06-21-20-15-004.png, image-2020-02-06-21-21-14-488.png
I try to load configuration from an external file on a fat jar.
I tried to load configuration from multiples methods without success.
I kept two methods on my sample:
{code:java}
if (!Files.isReadable(log4jConfiguration)) {
throw new IllegalStateException();
}
LOGGER.info("startup");
LOGGER.debug("startup"); // Not logged = OK
// First try to load configuration
Configurator.initialize(null, log4jConfiguration.toString());
LOGGER.debug("with init"); // Should be logged
// Second try to load configuration
// From log4j FAQ : https://logging.apache.org/log4j/2.x/faq.html#reconfig_from_code
final LoggerContext context = (LoggerContext) LogManager.getContext(false);
context.setConfigLocation(log4jConfiguration.toUri());
LOGGER.debug("reconfig from code"); // Should be logged
LOGGER.info("shutdown"); // Should be logged with [OUTER] prefix
{code}
The code works when running from IDE, but when executed with {{java -jar}} the external configuration is not loaded.
Result when running from IDE: !image-2020-02-06-21-20-15-004.png!
Result when running from jar: !image-2020-02-06-21-21-14-488.png!
I expect to have the configuration file loaded when running my jar file like when running from IDE.
Sample project to ease reproduction : [https://github.com/skyghis/testLog4j2]
--
This message was sent by Atlassian Jira
(v8.3.4#803005)