Logging

Berlioz provide several logging options.

Logging API

Berlioz uses SLF4J as a logging API, so the Java code is implemented against that:
  http://www.slf4j.org/docs.html 

To create a logger, you can declare a static variable in the generator

private final static Logger LOGGER = LoggerFactory.getLogger(MyGenerator.class);

Messages can then be logged with:

LOGGER.debug("something happened");
LOGGER.info("something happened...");
LOGGER.warn("something happened!!!");
LOGGER.info("{} happened", "Something");
...

See the API documentation for SLF4J for details:
  http://www.slf4j.org/apidocs/index.html 

Logging Configuration

LogBack

The logging framework (implementation) we recommend is Logback:
  http://logback.qos.ch/ 

At startup, Berlioz will automatically pick up the logging configuration from the config folder (/WEB-INF/config) as logback-[mode].xml

This is where you can configure your log and define where you want them to go. Typically, it is preconfigured to go to jetty/logs/[webappname] as .log files and rollover daily in production.

You can configure it to send it to a location of your choice or change the threshold level for particular packages if you need finer control.

See the manual for details:
   http://logback.qos.ch/manual/configuration.html 

Log4J

Alternatively, Berlioz can be configured to work with Apache Log4J 1.2. Simply put the log4j-[config].xml in the config folder.

Other frameworks

Berlioz can also be configured to work with other logging frameworks, but the configuration must be done independently.

Berlioz admin

The Berlioz admin tools should be able to locate the log files from the configuration and display them. When using Logback, they will also capture the most recent log messages and display them online regardless of the logging configuration.

Sample Logback configurations

Development mode

In development (or dev) mode, it is often useful to have a fine control of where the messages come from and have them send to Beagle or the console. Here is an example:

<configuration debug="false" scan="true" scanPeriod="30 seconds">
  <!-- Sends logs to Logback's Beagle Eclipse plugin -->
  <consolePlugin />

  <!-- Console appender -->
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>[%thread] %-5level %logger{30} - %msg %n</pattern>
    </encoder>
  </appender>

  <!-- Some libraries can be chatty... -->
  <logger name="net.sf.ehcache"       level="INFO" />
  <logger name="org.pageseeder.flint" level="WARN" />

  <!-- Berlioz and Bastille -->
  <logger name="org.pageseeder.berlioz" level="WARN" />
  <logger name="org.pageseeder.bastille" level="WARN" />
  <logger name="org.pageseeder.bastille.flint" level="WARN" />
  <logger name="org.pageseeder.bastille.cache" level="INFO" />
  <logger name="org.pageseeder.bastille.recaptcha" level="DEBUG" />

  <root level="DEBUG">
    <appender-ref ref="STDOUT"/>
  </root>
</configuration>

Production

In production, it is often preferable to have messages recorded on files:

<configuration debug="false">

  <!-- General Logs (text) -->
  <appender name="GENERAL" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <File>logs/myproject/berlioz.log</File>
    <Append>true</Append>
    <encoder>
      <pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <!-- rollover daily -->
      <fileNamePattern>logs/myproject/berlioz-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
      <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
        <!-- or whenever the file size reaches 100MB -->
        <maxFileSize>10MB</maxFileSize>
      </timeBasedFileNamingAndTriggeringPolicy>
    </rollingPolicy>
  </appender>

  <root level="INFO">
    <appender-ref ref="GENERAL"/>
  </root>
</configuration>

Note

The Berlioz admin tools should automatically capture the most recent logs events regardless of the configuration.

Created on , last edited on