The jadiceŽ document platform has a powerful logging framework facade which provides an easy and convenient way to integrate several different logging backends. The most common logging system is log4j. We would like to show how to optimize the log4j configuration in order to use it with the jadiceŽ document platform.
Please see the Using log4j section of the Logging getting started for the initial classpath setup.
At this point we are assuming the following basic configuration:
The configuration is expressed as a XML-document which is only one way to configure Log4J. All XML configuration examples may be easily converted to the corresponding configuration in properties format.
All examples are based on the following configuration. We are using one single appender called CONSOLE, which will simply print all output on the console.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration PUBLIC "-//Apache//DTD Log4j 1.2//EN" "http://logging.apache.org/log4j/docs/api/org/apache/log4j/xml/log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender class="org.apache.log4j.ConsoleAppender" name="CONSOLE"> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="[%-5p] %c %m%n" /> </layout> </appender> <!-- extensions will be added here --> <root> <level value="info" /> <appender-ref ref="CONSOLE" /> </root> </log4j:configuration>
Log4J uses logger names to configure the logging level, appenders and the like. The jadiceŽ document platform has got a naming convention regarding the class and package names. All classes have got a fully qualified class name starting with com.levigo. The logger name is always (with few exceptions) the class name of the logger class which is used for logging.
Example: If you would like to limit all logging of the jadiceŽ document platform to a level of ERROR and above, the following lines suffice:
<!-- [...] other configuration parts --> <logger name="com.levigo" additivity="true"> <level value="error"/> </logger> <!-- other configuration parts [...] -->
Using the additivity setting specifies that the configuration of the parent logger should be inherited. In this case the parent logger is the root logger. Due to that, there is no need to specify an appender explicitly since the CONSOLE appender has been inherited from the root logger. In this case we would override the logging level.
You should always be aware, that logging may significantly decrease application performance. Setting the level to DEBUG for all classes of the jadiceŽ document platform would significantly decrease the performance and should be avoided for production use.
Please be careful when selecting the elements which the log entry will consist of (like the class name, the date, etc.). The more information is being logged onto the console, the more the performance will be affected. Especially complex formatting possibilities provided by the PatternLayout should only be used, if really necessary.