Configuration path of Log4j2
Asked Answered
H

3

6

I am trying to adopt Log4j2 to my project. Since my Java Application is packeted in a JAR file. I don't want "log4j2.xml" configuration packaged inside of JAR file. I am trying to learn how configuration file works from "http://logging.apache.org/log4j/2.x/manual/configuration.html"

But seems there is no clear instruction regarding altering the configuration file path of the Log4j2.

After googling about this topic I found something like "Referencing log4j config file within executable JAR" Referencing log4j config file within executable JAR, But this solution is not available any more according to "http://logging.apache.org/log4j/2.x/manual/migration.html" (if I understand it correctly).

So I am wondering if someone have any idea about this issue.

Thanks

Harwilll answered 18/12, 2012 at 15:7 Comment(0)
A
9

You can set the system property to specify the configuration path. set the

"-Dlog4j.configurationFile="D:\learning\blog\20130115\config\LogConfig.xml" 

in VM arguments. replace

"D:\learning\blog\20130115\config\LogConfig.xml"

to your configuration path.

Aquaplane answered 15/1, 2013 at 10:51 Comment(0)
G
2
  1. Put the log4j2.xml file in resource directory in your project so that the log4j will locate files under class path automatically.

Loading log4j2.xml file from the customized location-

  1. You can use the System property/ VM arguments- Dlog4j.configurationFile=file:/path/to/file/log4j2.xml This will work for any web application.

  2. For some legacy applications, you can create a class for loading log4j2.xml/ log4j2.properties from the custom location on the machine like- D:/property/log4j2.xml Using any of these approach,during application startup, the log4j2.xml file from the src/resources folder will be overridden by the custom location log4j.xml file.

Gubernatorial answered 22/4, 2021 at 15:25 Comment(0)
S
1

Try using -Dlogging.config=Path_to_your_file

Stateless answered 24/1, 2019 at 22:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.