Context Based Logging - BloomReach Experience - Open Source CMS

This article covers a Hippo CMS version 10. There's an updated version available that covers our most recent release.

12-05-2015

Context Based Logging

Even though the logging configuration for the CMS version before 7.9.0 in archetype created projects was designed to keep context-based separate log files (e.g, hippo-cms.log for cms/repo application and hippo-site.log for site application), the solution didn't provide the designed feature properly.  

For example, if you used hippo-repository-connector classes in an HST component, then you will see the logs generated by the 

hippo-repository-connector classes in the hippo-cms.log file and not in the hippo-site.log file because default configuration for log4j was not so flexible and so it is strictly tied to the class/package names only. 

Another example is logs from freemarker templates : If both CMS webapp and site webapp run freemarker templates, both webapps log to the same log file.

Context Based Logging

To overcome the above described problem, the archetype created project now by default is configured with Context Based Logging. This way, logging that originated from site webapp always end up in the site.log, and similar for the CMS webapp. 

How to

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>
Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?