Context-Based Logging
Introduction
Projects created using Hippo's Maven archetype include default log4j configuration files that use context-based logging. This means that log messages that originate in the site webapp always end up in hippo-site.log, while those that originate in the cms webapp end up in hippo-cms.log.
The default log4j configuration files are:
- conf/log4j-dev.xml
Used when running in a local Cargo-based development environment. Configures daily log file rollover and includes sensible log levels for development. Also includes a console appender which logs to the command line console in which the application is running. - conf/log4j-dist.xml
Optimized for production environments and included when creating a project distribution. Configures log file rollover based on size and includes only log levels that are relevant in production environments.
If your project was not created using the archetype, or was created using an older version of the archetype, you can update your log4j configuration to reflect current best practice by following the instructions on this page.
Configure Log4j
Make sure that in the log4j.xml files the cms and site appenders have the MdcOrJndiPropertyFilter filter below:
<!-- hippo-cms.log --> <appender name="cms" class="org.apache.log4j.DailyRollingFileAppender"> <param name="File" value="${catalina.base}/logs/hippo-cms.log"/> <param name="Append" value="true"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{dd.MM.yyyy HH:mm:ss} %-5p %t [%C{1}.%M:%L] %m%n"/> </layout> <filter class="org.onehippo.cms7.logging.log4j.MdcOrJndiPropertyFilter"> <param name="name" value="logging/contextName" /> <param name="resourceRef" value="true" /> <param name="value" value="cms" /> <param name="onMatchOption" value="ACCEPT" /> </filter> </appender> <!-- hippo-site.log --> <appender name="site" class="org.apache.log4j.DailyRollingFileAppender"> <param name="File" value="${catalina.base}/logs/hippo-site.log"/> <param name="Append" value="true"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{dd.MM.yyyy HH:mm:ss} %-5p %t [%C{1}.%M:%L] %m%n"/> </layout> <filter class="org.onehippo.cms7.logging.log4j.MdcOrJndiPropertyFilter"> <param name="name" value="logging/contextName" /> <param name="resourceRef" value="true" /> <param name="value" value="site" /> <param name="onMatchOption" value="ACCEPT" /> </filter> </appender>
Add to the end of the web.xml of the cms webapp the following part:
<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>
And add to the end of the web.xml of the site webapp the following part:
<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>