Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change configuration of log4j in runtime

I have a command line application in which I have enabled log4j. For now only file logging is added. Now I want that, without restarting or recompiling jar file I should be able to change configuration of log4j.

I read in log4j manual that it can automatically detect changes in config file. So how can I put config file in some separate location and have it's changes reflected in runtime in the application?

like image 622
Shades88 Avatar asked Jan 22 '26 06:01

Shades88


1 Answers

There are many ways to do this. They are covered in the log4j configuration guide.

The simplest is to put a log4j.xml on the classpath. Then add the monitorInterval="30" attribute to the opening configuration tag. This tells log4j to check the file for changes every 30 seconds.

like image 113
Brett Okken Avatar answered Jan 23 '26 19:01

Brett Okken