eXo Platform 3.0

- Prev
- Next

## Chapter 58. Logs configuration

## Introdution

In order to accommodate to the different target runtime where it can be deployed, eXo is capable of leveraging several logging systems. eXo lets you choose the underlying logging engine to use and even configure that engine (as a quick alternative to doing it directly in your runtime environment).

The currently supported logging engines are :

- Apache Log4J

- JDK's logging

- Apache Commons logging (which is itself a pluggable logging abstraction)

## Logs configuration initializer

eXo lets you choose whatever logging engine you want as this is generally influences by the AS runtime or internal policy.

This is done through an eXo component called `LogConfigurationInitializer`.

`org.exoplatform.services.log.LogConfigurationInitializer` that reads init parameters and configures logging system according to them. The parameters:

- configurator - an implementation of the `LogConfigurator` interface with one method configure() that accepts a list of properties (3rd init parameter) to configure the underlying log system using the concrete mechanism. Again, there are three configurators for the most known log systems (commons, log4j, jdk).

- properties - properties to configure the concrete log system (system properties for commons, log4j.properties or logging.properties for commons, log4j and jdk respectively) Look at the configuration examples below.

- logger - an implementation of commons-logging Log interface. It is possible to use commons wrappers but to support buffering required by the log portlet three kinds of loggers were added: `BufferedSimpleLog`, `BufferedLog4JLogger` and `BufferedJdk14Logger` (they contain BufferedLog and extend SimpleLog, Log4JLogger and Jdk14Logger commons-logging wrappers respectively).

## Configuration examples

### Log4J

Log4J is a very popular and flexible logging system. It is a good option for JBoss.

      <component>
        <type>org.exoplatform.services.log.LogConfigurationInitializer</type>
        <init-params>
          <value-param>
            <name>logger</name>
            <value>org.exoplatform.services.log.impl.BufferedLog4JLogger</value>
          </value-param>
          <value-param>
            <name>configurator</name>
            <value>org.exoplatform.services.log.impl.Log4JConfigurator</value>
          </value-param>
          <properties-param>
            <name>properties</name>
            <description>Log4J properties</description>
            <property name="log4j.rootLogger" value="DEBUG, stdout, file"/>
            <property name="log4j.appender.stdout" value="org.apache.log4j.ConsoleAppender"/>
            <property name="log4j.appender.stdout.layout" value="org.apache.log4j.PatternLayout"/>
            <property name="log4j.appender.stdout.layout.ConversionPattern" value="%d {dd.MM.yyyy HH:mm:ss} %c {1}: %m (%F, line %L) %n"/>
            <property name="log4j.appender.file" value="org.apache.log4j.FileAppender"/>
            <property name="log4j.appender.file.File" value="jcr.log"/>
            <property name="log4j.appender.file.layout" value="org.apache.log4j.PatternLayout"/>
            <property name="log4j.appender.file.layout.ConversionPattern" value="%d{dd.MM.yyyy HH:mm:ss} %m (%F, line %L) %n"/>
          </properties-param >
        </init-params>
      </component>

#### Assigning logger level for classes or components

You can set logger level for class or group of classes by setting next property:

    <property name="log4j.category.{component or class name}" value="DEBUG"/>

For example:

- We want to log all debug messages for class `org.exoplatform.services.jcr.impl.core.SessionDataManager`, that lies in exo.jcr.component.core component

      <property name="log4j.category.exo.jcr.component.core.SessionDataManager" value="DEBUG"/>

- Or we want to log all debug messages for all classes in in exo.jcr.component.core component

      <property name="log4j.category.exo.jcr.component.core" value="DEBUG"/>

- Or we want to log all messages for all kernel components

      <property name="log4j.category.exo.kernel" value="DEBUG"/>

### JDK Logging

JDK logging (aka JUL) is the builtin logging framework introduced in JDK 1.4. It is a good option for Tomcat AS.

- Edit the variable `LOG_OPTS` in your `eXo.sh` or `eXo.bat` :

      LOG_OPTS="-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger"

- Edit your `logs-configuration.xml` :

      <component>
          <type>org.exoplatform.services.log.LogConfigurationInitializer</type>
          <init-params>
            <value-param>
              <name>logger</name>
              <value>org.exoplatform.services.log.impl.BufferedJdk14Logger</value>
            </value-param>
            <value-param>
              <name>configurator</name>
              <value>org.exoplatform.services.log.impl.Jdk14Configurator</value>
            </value-param>
            <properties-param>
              <name>properties</name>
              <description>jdk1.4 Logger properties</description>
              <property name="handlers" value="java.util.logging.ConsoleHandler"/>
              <property name=".level" value="FINE"/>
              <property name="java.util.logging.ConsoleHandler.level" value="FINE"/>
            </properties-param>
          </init-params>
        </component>

### Commons Logging SimpleLogss

SimpleLog is a minimal logging system distributed with Commons Logging. To be used when nothing else is available or when you seek simplicity.

      <component>
        <type>org.exoplatform.services.log.LogConfigurationInitializer</type>
        <init-params>
          <value-param>
            <name>logger</name>
            <value>org.exoplatform.services.log.impl.BufferedSimpleLog</value>
          </value-param>
          <value-param>
            <name>configurator</name>
            <value>org.exoplatform.services.log.impl.SimpleLogConfigurator</value>
          </value-param>
          <properties-param>
            <name>properties</name>
            <description>SimpleLog properties</description>
            <property name="org.apache.commons.logging.simplelog.defaultlog" value="debug"/>
            <property name="org.apache.commons.logging.simplelog.showdatetime" value="true"/>
          </properties-param>
        </init-params>
      </component>

## Tips and Troubleshooting

### JBoss tips

If you use log4j configuration, you can change the log configuration directly at runtime in: `JBOSS_HOME/server/default/conf/jboss-log4j.xml`.

- To enable debug logs :

       <param name="Threshold" value="DEBUG"/>

- To exclude messages from unnecessary classes (server's internal) modify the threshold of these classes to "FATAL".

### Tip

If you see only ERROR level logs while starting ear on jboss (4.2.2), you have to remove log4j*.jar from your ear and application.xml.

### Other tips

If you see only ERROR level logs while starting ear on jboss (4.2.2), you have to remove log4j*.jar from your ear and application.xml.

- Prev
- Up
- Home
- Next