Page tree
Skip to end of metadata
Go to start of metadata

This task is in progress at Magnolia Inc. see:  MAGNOLIA-6794 - Getting issue details... STATUS  and Log4j2 upgrading

Those of you interested in upgrading to log4j2 sooner may be interested in these notes.

Motivation

log4j1 is end of life, and new developments are happening in log4j2. Requirements from operations for centralized logging are the motivation to upgrade at this point. The Appenders for writing to central logging solutions are much more available for log4j2.

Basic setup

Alter your maven configuration (you're building your magnolia WARs via Maven, right?) to include the new log4j2 JARs:

		    <dependency>
		      <groupId>org.apache.logging.log4j</groupId>
		      <artifactId>log4j-api</artifactId>
		      <version>${log4j2.version}</version>
		    </dependency>
		    <dependency>
		      <groupId>org.apache.logging.log4j</groupId>
		      <artifactId>log4j-core</artifactId>
              <version>${log4j2.version}</version>
		    </dependency>
		    <dependency>
		      <groupId>org.apache.logging.log4j</groupId>
		      <artifactId>log4j-1.2-api</artifactId>
              <version>${log4j2.version}</version>
		    </dependency>         
		    <dependency>
		      <groupId>org.apache.logging.log4j</groupId>
		      <artifactId>log4j-jcl</artifactId>
              <version>${log4j2.version}</version>
		    </dependency>
		    <dependency>
		      <groupId>org.apache.logging.log4j</groupId>
		      <artifactId>log4j-slf4j-impl</artifactId>
              <version>${log4j2.version}</version>
		    </dependency>
		    <dependency>
		      <groupId>org.apache.logging.log4j</groupId>
		      <artifactId>log4j-jul</artifactId>
              <version>${log4j2.version}</version>
		    </dependency>

Then check your project dependency tree, and add exclusions like this to exclude the old log4j libraries:

            <exclusions>
	          <exclusion>
	              <groupId>org.slf4j</groupId>
	              <artifactId>slf4j-log4j12</artifactId>
	          </exclusion>
              <exclusion>
	            <groupId>log4j</groupId>
	            <artifactId>log4j</artifactId>
	          </exclusion>      
	        </exclusions>

Configuration file

Magnolia is working on making log4j interact with magnolia in the usual way via configuration from the magnolia.properties files. In the meantime, you can add the following to your tomcat startup to configure the location of log4j2:

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

A sample configuration file with Magnolia's standard settings can be found here: https://git.magnolia-cms.com/users/ngoc.nguyenthanh/repos/main/browse/magnolia-core/src/main/resources/log4j2-webapp.xml?at=b4b236f578e656b08c154007800b5f244179fca4

Running

Fire up magnolia and you should see your standard log files, now written via log4j2. You can make use of log4j2's new features and appenders.

The log-tools app is not working in this configuration, but you can change the log-levels in the XML configuration file, and they will be dynamically reloaded by log4j2.

Update: here is a patched version of the log-tools app you can use: https://git.magnolia-cms.com/users/runger/repos/log-tools/browse?at=refs%2Fheads%2Flog4j2 
This patched version works fine with log4j2.


  • No labels