Change Location of Log4J.Properties

Change location of log4j.properties

Yes, define log4j.configuration property

java -Dlog4j.configuration=file:/path/to/log4j.properties myApp

Note, that property value must be a URL.

For more read section 'Default Initialization Procedure' in Log4j manual.

How can I change the name and location of log4j.properties?

You can change its location like so:

java -Dlog4j.configuration=file:/path_to_file_here/log4j.properties YourApplication

You should also read the manual.

Regarding changing the name, this is how you can achieve this:

First, you must add the following line to your java runtime command:

-Dlog4j.configuration=test.properties

For example lets assume you are using log4j in your web application deployed on Tomcat.
Add the above mentioned line in the java runtime command to start up Tomcat:

C:\Tools\java\j2sdk1.4.2_01\bin\java.exe -jar
-Duser.dir="C:\Tools\Tomcat 4.1"
-Dlog4j.configuration=test.properties
-Djava.endorsed.dirs="C:\Tools\Tomcat 4.1\common\endorsed"
"C:\Tools\Tomcat 4.1\bin\bootstrap.jar" start

You will also possibly want to read this.

How to change location of log4j.properties in a Maven project?

Problem solved. Some lines were missing on my POM file, directly in the project tree.

<properties>
<log4j.configuration>conf/log4j.properties</log4j.configuration>
</properties>

How can I change the default location of log4j2.xml in Java Spring Boot?

As specified in the Spring reference documentation, the logging.config property cannot be set among the application properties, as they are read after the logging has already been initialised.

The solution is to provide the path to the external logging configuration this way:

java -Dlogging.config='/path/to/log4j2.xml' -jar app-current.jar

How to specify Log4J 2.x config location?

You could use the static method #initialize(String contextName, ClassLoader loader, String configLocation) (see source here) in org.apache.logging.log4j.core.config.Configurator.
(You can pass null for the class loader.)

Be aware that this class is not part of the public API so your code may break with any minor release.

For completeness, you can also specify the location of the configuration file with this system property:

-Dlog4j.configurationFile=path/to/log4j2.xml

How to add path of log4j.properties file in my project classpath in eclipse?

Right click on the folder, select Build Path then Use as a Source Folder.

Just remember that when you will deploy you will need to create a directory for resources and add it to class path.

You should also consider to use maven for your java project, it may seem overkill initially but it will pay off in the long run.

Where is the correct location to put Log4j.properties in an Eclipse project?

you can add it any where you want, when you run your project, configure the classpath and add the location of the log4j.properties files by clicking on:
Run->Run Configuration -> [classpath tab] -> click on user Entries -> Advanced -> Select Add Folder -> select the location of your log4j.properties file

and then -> OK -> run

and it should get loaded

How to change the path of the log4j.properties file to a specific one?

Set following context param:

  <context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/config/log4j/log4j.properties</param-value>
</context-param>

Don't forget to add

 <listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

in web.xml



Related Topics



Leave a reply



Submit