Migrating a custom logging configuration to Log4j 2

On this page

Still need help?

The Atlassian Community is here for you.

Ask the community

In Crowd 5.2, we’ve upgraded the Log4j runtime library to version 2. If you have a custom Log4j configuration in your Crowd instance, you need to manually migrate it to the new file format.

If you didn’t customize the configuration, you can skip this page. You’ll automatically start using the new version after upgrading Crowd.

To learn more about what’s new in Log4j 2, see Apache Log4j 2.

Step 1: Migrate logging level configuration

In the following example, we’ll migrate the HttpRequestLoggingFilter class logging level configuration.

In V1:

In Log4j 1.x, the logging level configuration for the HttpRequestLoggingFilter class would look like this:

log4j.logger.com.atlassian.crowd.plugin.web.filter.HttpRequestLoggingFilter=INFO

In V2:

The same configuration in Log4j 2 requires that we migrate the HttpRequestLoggingFilter category configuration to a logger under the name http-request-logging-filter:

logger.http-request-logging-filter.level=INFO
logger.http-request-logging-filter.name=com.atlassian.crowd.plugin.web.filter.HttpRequestLoggingFilter

As part of this migration, we gave the new logger the following properties:

  • level defines the logging level (in this case, the logging level is INFO)

  • name indicates the class we are configuring the logging level for (in this case, com.atlassian.crowd.plugin.web.filter.HttpRequestLoggingFilter)

Step 2: Migrate the Log4j appender configuration

Log4j 2 also introduced changes to the definitions of appender properties. To illustrate the migration process, let’s use an example where we migrate the Log4j2CrowdHomeLogAppender appender, but keep the same configuration as in Log4j 1.x.

In V1:

Here’s how the Log4j2CrowdHomeLogAppender appender configuration would look in Log4j 1.x:

log4j.appender.crowdlog=com.atlassian.crowd.console.logging.CrowdHomeLogAppender
log4j.appender.crowdlog.MaxFileSize=20480KB
log4j.appender.crowdlog.MaxBackupIndex=5
log4j.appender.crowdlog.layout=org.apache.log4j.PatternLayoutlog4j.appender.crowd
log.layout.ConversionPattern=%d %t %p [%c{4}] %m%n
log4j.appender.crowdlog.filter.1=com.atlassian.crowd.console.logging.HibernateLogSuppressingMdcFilter

In V2:

Here’s how the same appender configuration looks after being migrated to a format compatible with Log4j 2:

appender.crowdlog.type=Log4j2CrowdHomeLogAppender
appender.crowdlog.name=crowdlog
appender.crowdlog.layout.type=PatternLayout
appender.crowdlog.layout.pattern=%d %t %p [%c{4}] %m%n
appender.crowdlog.policies.type=Policies
appender.crowdlog.policies.size.type=SizeBasedTriggeringPolicy
appender.crowdlog.policies.size.size=20480KB
appender.crowdlog.strategy.type=DefaultRolloverStrategy
appender.crowdlog.strategy.max=5
appender.crowdlog.strategy.fileIndex=min

Once you’ve completed the steps above, your custom configuration should be compatible with Log4j 2.

Last modified on Jun 22, 2023

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.