Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change location of log4j.properties

Tags:

java

log4j

I want to put all my config files in a /config subfolder of my application directory. Log4j is expecting the log4j.properties file in the root folder of my application. Is there a way to tell log4j where to look for the properties file?

like image 309
markus Avatar asked Sep 12 '11 15:09

markus


People also ask

How do you set a log4j properties file location?

The file is named log4j. properties and is located in the $DGRAPH_HOME/dgraph-hdfs-agent/lib directory. The file defines the ROLLINGFILE appenders for the root logger and also sets the log level for the file. The level of the root logger is defined as INFO and attaches the ROLLINGFILE appender to it.

How do I change the log4j properties at runtime?

Use LogManager. resetConfiguration(); to clear the current config and configure it again. Another approach is to build a new appender and replace the old one with it (most appenders don't support changing their config). This way, all the loggers (and their levels, etc) stay intact.

How do you set log file path in log4j properties dynamically?

System. setProperty("{my. log", "C:/logfile. log");


1 Answers

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.

like image 76
Alexander Pogrebnyak Avatar answered Sep 20 '22 19:09

Alexander Pogrebnyak