This article covers a Bloomreach Experience Manager version 11. There's an updated version available that covers our most recent release.

Add host information to logging

In a situation where you run multiple subsites, it can be very useful to know at which subsite(host) an error has occurred. You can modify your log pattern for this, to always prefix the log entry with the hostname of the subsite. Thus, for example, in your log4j.xml use:

<!-- 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="com.onehippo.logging.HostPatternLayout">
      <param name="ConversionPattern"
             value="%h %d{dd.MM.yyyy HH:mm:ss} %-5p [%C.%M():%L] %m%n"/>
    <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" />

This is quite easy to do by using following layout pattern:

package com.onehippo.logging;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.helpers.PatternConverter;
import org.apache.log4j.helpers.PatternParser;
import org.apache.log4j.spi.LoggingEvent;
import org.hippoecm.hst.container.RequestContextProvider;
import org.hippoecm.hst.core.container.HstContainerURL;
import org.hippoecm.hst.core.request.HstRequestContext;

 * Adding a hostname pattern to log4j pattern: <strong>{@code h}</strong>
 * <p/>
 * Usage example:
 * <pre>
 * <strong>
 *    &lt;layout class="com.onehippo.logging.HostPatternLayout"&gt;
 *       &lt;param name="ConversionPattern" value="%h -
 *            %d{dd.MM.yyyy HH:mm:ss} %-5p [%C.%M():%L] %m%n"/&gt;
 *     &lt;/layout&gt;
 * </strong>
 * </pre>
 * @version "$Id$"
public class HostPatternLayout extends PatternLayout {

  protected PatternParser createPatternParser(final String pattern) {
    return new PatternParser(pattern) {
      protected void finalizeConverter(char c) {
        PatternConverter patternConverter = null;
        if (c == 'h') {
          patternConverter = new PatternConverter() {
            protected String convert(LoggingEvent event) {
              HstRequestContext context = RequestContextProvider.get();
              if (context != null) {
                final HstContainerURL baseURL = context.getBaseURL();
                if (baseURL != null) {
                  return baseURL.getHostName();
              return "";

        if (patternConverter == null) {
        } else {


Compile time dependencies are required for:


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?