Prerequisites
We need a unified, simple and fast way for logging application activities. The proposed framework should also be simple enough to configure and use different Logging libraries, such as: Apache Commons logging (which itself can be used as an entry point to an underlying logger), Apache Log4J and JDK's logging.Logger framework
The Logger service consists of: org.exoplatform.services.log.LogConfigurationInitializer that reads init parameters and configures logging system according to them. The parameters:- logger - an implementation of commons-logging Log. 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)
- 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
- ExoLogger.getLogger(Class)
- ExoLogger.getLogger(String)
How to use
The framework uses the Commons - Logging library. Make sure you understand how to configure and use it. It is not really neccessary to know all its aspects, just configuration and usage should be enough. In case of using Log4J or JDK's logger familiarize with their configuration parameters as well.- Configure a logger you want to use (see also Configuration examples)
- Add a (preferably static to make it faster) Log variable, for example
- Use this log with desired logging level, for example
Configuration example
<component>
<type>org.exoplatform.services.log.LogConfigurationInitializer</type>
<init-params>
<!-- Log4J: -- >
<!-- 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 -->
<! -- Commons Simple: -- >
<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>
<! -- JDK: -- >
<! -- 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>
Example:
For debug ecm on tomcat you have to modify the file conf/configuration.xml within exo.kernel.component.common-*.jar
For JBoss
To increase the log verbosity for diagnostics purposes
JBOSS_HOME/server/default/conf/jboss-log4j.xml
<param name="Threshold" value="DEBUG"/>You do not even need to change the http://fisheye.exoplatform.org /browse/projects/kernel/trunk/component/common/ src/main/java/conf/configuration.xml To exclude messages from unnecessary classes (server's internal) to modify other categories to "FATAL" priority. btw, 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.
on 23/07/2008 at 05:51