Context-Based Logging

Overview

Bloomreach Experience Manager projects created with the Maven archetype include default Log4j 2 configuration files that implement context-based logging. With this setup, log messages from the site web application are written to site.log, and messages from the cms web application are written to cms.log.

The default Log4j 2 configuration files are:

  • conf/log4j2-dev.xml
    Used in local Cargo-based development environments when running the project. This configuration enables daily log file rollover, sets log levels suitable for development, and includes a console appender that outputs logs to the terminal.
  • conf/log4j2-dist.xml
    Used for production environments and included when creating a project distribution. This configuration rolls log files based on size and limits log levels to those appropriate for production.

If your project was not generated with the Maven archetype, or uses an older archetype version, update your Log4j configuration as described below to follow current best practices.

Log4j 2 Configuration

In your log4j2-*.xml files, ensure that the cms and site appenders use the following LookupFilter configuration:

<Appenders> <!-- cms.log --> <RollingFile name="cms" fileName="${sys:catalina.base}/logs/cms.log" filePattern="${sys:catalina.base}/logs/cms.log.%d{yyyy-MM-dd}"> <LookupFilter key="jndi:logging/contextName" value="cms" onMatch="ACCEPT"/> <PatternLayout pattern="%d{dd.MM.yyyy HH:mm:ss} [%t] %-5p [%C.%M():%L] %m%n"/> <Policies> <SizeBasedTriggeringPolicy size="10MB"/> </Policies> <DefaultRolloverStrategy max="1" fileIndex="min"/> </RollingFile> <!-- site.log --> <RollingFile name="site" fileName="${sys:catalina.base}/logs/site.log" filePattern="${sys:catalina.base}/logs/site.log.%d{yyyy-MM-dd}"> <LookupFilter key="jndi:logging/contextName" value="site" onMatch="ACCEPT"/> <PatternLayout pattern="%d{dd.MM.yyyy HH:mm:ss} [%t] %-5p [%C.%M():%L] %m%n"/> <Policies> <SizeBasedTriggeringPolicy size="10MB"/> </Policies> <DefaultRolloverStrategy max="4" fileIndex="min"/> </RollingFile> </Appenders>

Add the following entry at the end of the web.xml file for the cms web application:

<env-entry> <env-entry-name>logging/contextName</env-entry-name> <env-entry-type>java.lang.String</env-entry-type> <env-entry-value>cms</env-entry-value> </env-entry>

Add the following entry at the end of the web.xml file for the site web application:

<env-entry> <env-entry-name>logging/contextName</env-entry-name> <env-entry-type>java.lang.String</env-entry-type> <env-entry-value>site</env-entry-value> </env-entry>

Warning: Starting with versions 12.6.22, 13.4.13, and 14.7.2, the LookupFilter class only supports JNDI lookup for the key "logging/contextName". If you use any other JNDI name, the lookup will fail and all log messages will be suppressed.

Share Feedback
Page: /deploy/on-premise-deployment/deployment-overview/context-based-logging
Section: Deploy
Category *