XWiki uses SLF4J for logging. By default XWiki is configured so that SLF4J uses Logback. XWiki's Logback configuration is located in the WEB-INF/classes/logback.xml file.

XWiki is also configured by default so that any logs generated by 3rd part JARs used by XWiki (i.e. in the XWiki classpath at runtime) will automatically find their ways to the output defined by the Logback configuration file. This is active for Apache Commons Logging (JCL) and Log4J. This is achieved by using a SLF4J Bridge for both logging frameworks (it's the log4j-over-slf4j-*.jar and jcl-over-slf4j-*.jar files that provide this feature).

By default XWiki is configured to log everything on the console only. Whether the console is captured by your Servlet Container or not depends on the container you use. For example Tomcat on unix will capture stdout and add logs to the tomcat/logs/catalina.out file.

Configuring Logging

There are various ways in which you can configure what to log.

See also the Logging section of the Debugging page for specific details on some loggers.

Of the 3 methods proposed under, only the Manual method is persistent after a server restart. So if your server might restart/be restarted and you want the log configuration to be kept after this restart, the only method is adding them to logback.xml.

Manually

Simply edit the Logback configuration file  (logback.xml in WEB-INF/classes in your web application folder) and restart the Servlet container for it to take effect.

Using the Log Application

Starting with XWiki 4.2 a new Logging Application is available in your wiki's administration UI and you can use it to configure the log levels for all features.

Using JMX

LogBack exposes its configuration with JMX making it possible to use a JMX console to modify the logging configuration at runtime, thus not needing to restart the Servlet container. This is very useful in production when needing to debug an issue.

See the Monitoring Guide for more details on using JMX with XWiki.

Analyzing logs with Lilith

Lilith is a logging and access event viewer. It makes it easy to analyze large quantities of logs. To use it, configure XWiki's Logging to send events to the Socket appender. Add the following to the logback.xml file:

...
 <appender name="socket" class="ch.qos.logback.classic.net.SocketAppender">
   <RemoteHost>localhost</RemoteHost>
   <Port>4560</Port>
   <ReconnectionDelay>170</ReconnectionDelay>
   <IncludeCallerData>true</IncludeCallerData>
 </appender>
...

And add the new appender to the list of appenders to use. For example:

...
 <root level="warn">
   <appender-ref ref="stdout"/>
   <appender-ref ref="socket"/>
 </root>
...

Open Lilith (it's a desktop application) and it'll automatically listen on port 4560 so when you start XE you'll see its logs show up in Lilith.

For example:

lilith.png

Using a different SLF4J implementation

If you wish, for example, to use Log4J to log all logs produced by XWiki you can do so by doing the following (described in the SLF4J manual):

  • Remove the Logback SLF4J implementation from the classpath by removing WEB-INF/lib/logback-classic-*.jar and WEB-INF/lib/logback-core-*.jar
  • Remove the Log4J over SLF4J JAR from the classpath by removing WEB-INF/lib/log4j-over-slf4j-*.jar
  • Add the Log4J SLF4J implementation to the classpath: slf4j-log4j*-*.jar
  • Add Log4J itself to the classpath

Older XWiki versions

XWiki versions 3.0 and older use Commons Logging for logging. By default XWiki was configured so that Commons Logging was using log4J. XWiki's Log4J configuration was located inside XWiki's JAR (xwiki-core-x.y.jar), in a log4j.properties file. XWiki' JAR is itself located in your WEB-INF/lib/ directory.

By default XWiki was configured to log everything on the console only.

Using a custom Log4J configuration

The best solution was to create a new log4j.properties file in your WEB-INF/classes directory. It'll thus override the one from the XWiki JAR. As an example, here's a sample configuration:

### Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%X{url}] [%t] %-5p %-30.30c{2} %x - %m %n

### By default everything that is of warning or severity WARN, ERROR or FATAL is logged both to
### the console and to the xwiki.log file.
log4j.rootLogger=warn, stdout

### Hibernate logging options
log4j.logger.org.hibernate=warn
log4j.logger.org.hibernate.SQL=warn
log4j.logger.org.hibernate.type=warn
log4j.logger.org.hibernate.ps.PreparedStatementCache=warn

### XWiki logging configuration
log4j.logger.org.xwiki=info
log4j.logger.com.xpn.xwiki=warn
log4j.logger.com.xpn.xwiki.render.XWikiRadeoxRenderEngine=warn
log4j.logger.com.xpn.xwiki.store.migration=info

### Deactive Struts warnings
log4j.logger.org.apache.struts.util.RequestUtils=error

### Deactivate JGroups warnings
log4j.logger.org.jgroups=error

## Deactive PDF Export CSS Applier warnings
log4j.logger.info.informatica.doc.style.css.dom=error
log4j.logger.org.apache.fop.layoutmgr.inline.ContentLayoutManager=error

Refer to Log4J's documentation to understand the settings. As an example, to turn on Hibernate's calls, just set the following:

log4j.logger.org.hibernate.SQL=debug

Activating the XWiki Monitoring feature

The monitoring feature is already active in the default configuration.

XWiki has a feature to monitor times spent in its major components. To activate it, you need to:

  • Enable the Monitor plugin by adding/modifying the following plugin definition in the xwiki.cfg configuration file:
    xwiki.plugins=\
       [...]
       com.xpn.xwiki.monitor.api.MonitorPlugin
  • Enable it by adding/modifying the following in the xwiki.cfg configuration file:
    xwiki.monitor=1
  • Since the plugin logs everything under the DEBUG severity you also need to configure the XWiki Logging (as described above) by setting the com.xpn.xwiki.monitor category to the DEBUG level.

    For example for Logback it means adding the following in logback.xml:

    <logger name="com.xpn.xwiki.monitor" level="debug"/>

    And for older XWiki versions using Log4J it means adding the following in log4j.properties:

    log4j.logger.com.xpn.xwiki.monitor=debug
Tags:
Created by Vincent Massol on 2017/09/06
   

Get Connected