Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j2 properties | monitorInterval not working

Tags:

java

log4j

log4j2

I am using log4j 2.4 and trying to convert log4j2.xml to log4j.properties, however monitorInterval property doesn't seem to be working with log4j2.properties.

  • status = trace
  • name=PropertiesConfig
  • property.filename = logs
  • appenders = console, file
  • monitorInterval=10

though log4j2 following documentation https://logging.apache.org/log4j/2.x/manual/configuration.html#Properties

clearly stats that

Properties configuration files support the advertiser, monitorInterval, name, packages, shutdownHook, status

any changes in property file doesn't leads to reloading of logging configuration. On the contrary, it seems to be perfectly working in xml format

<Configuration status="TRACE" monitorInterval="5">

where whenever I do make any changes in .xml my log4j configuration is picked up and is verified via following log.

2016-06-17 14:43:17,267 Thread-5 DEBUG Reconfiguration started for context 1198108795 (org.apache.logging.log4j.core.LoggerContext@86be70a)
2016-06-17 14:43:17,268 Thread-5 DEBUG Not in a ServletContext environment, thus not loading WebLookup plugin.

2016-06-17 14:43:17,273 Thread-5 DEBUG Initializing configuration XmlConfiguration[location=/Users/userx/Desktop/logs/log4j2_prod.xml]

I also tried to upgrade Log4j version to 2.5 but still observe same behavior.

like image 691
tarunkumar Avatar asked Jun 17 '16 23:06

tarunkumar


People also ask

Does Log4j properties work with log4j2?

Log4j 2 doesn't support the Log4j v1 ". properties" format anymore (yet, since v2. 4, Log4j supports a Property format, but its syntax is totally different from v1 format). New formats are XML, JSON, and YAML, see the documentation (note: if you used one of these formats in a file called ".

Where do log4j2 properties go?

We should put log4j2. properties anywhere in the application's classpath. Log4j2 will scan all classpath locations to find out this file and then load it. We have put the file in resources folder.

What is status in log4j2 properties file?

Configuration: the root element of a log4j2 configuration file; the status attribute represents the level at which internal log4j events should be logged. Appenders: this element contains a list of appenders; in our example, an appender corresponding to the System console is defined.

Where is Log4j properties file located?

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.


2 Answers

To add to Ralph's answer, this was fixed in Log4j 2.6. The corresponding ticket is https://issues.apache.org/jira/browse/LOG4J2-1263

Please use Log4j-2.6.1 or later.

like image 109
Remko Popma Avatar answered Oct 16 '22 06:10

Remko Popma


This was a bug that has been fixed. I would suggest updating the latest log4j release.

like image 30
rgoers Avatar answered Oct 16 '22 04:10

rgoers