Logging Module

The Logging module allows XWiki components to receive logs as events and to isolate logs in for a specific task without them appearing in the standard log. The Logging module was designed to work with the Logging Application. The source code of the UI is published on GitHub.

The available logging levels are: TRACE, DEBUG, INFO, WARN and ERROR.

The Logging module does not provide logs for Components. To do do, you need to inject a SLF4J Logger, as explained in the dedicated documentation page.

The source code for the Logging module API is also published on GitHub

Receive Logs as Events

In order for a component to receive logs, it must listen to events of type LogEvent as shown in the below code snippet. More details are available in the documentation page about the Observation Module.

import org.xwiki.logging.LogLevel;
import org.xwiki.logging.event.AbstractLogEventListener;
import org.xwiki.observation.event.Event;

public class CustomLogListener extends AbstractLogEventListener
  public String getName()
      return "CustomLogListener";

  public void onEvent(Event event, Object source, Object data)
        LogEvent logEvent = (LogEvent) event;

      if (logEvent.getLevel() == LogLevel.ERROR) {
      } else if (logEvent.getLevel() == LogLevel.WARN) {
      } else if (logEvent.getLevel() == LogLevel.INFO) {
      } else if (logEvent.getLevel() == LogLevel.DEBUG) {
      } else if (logEvent.getLevel() == LogLevel.TRACE) {

Isolate Error Logs

To isolate specific logs, like for instance error messages, you can use the LoggerManager component.

LogQueue queue = new LogQueue();

loggerManager.pushLogListener(new LogQueueListener("loglistenerid", queue));
logger.error("Some application error happen");

The pushLogListener() method retrieves the logs generated by the current thread and sends them to the provided listener. The logs will then be received as XWiki events.

The popLogListener() method removes the current listener from the current thread stack and returns the previous log event listener for the current thread. In case several listeners have been pushed, the previous one becomes active.

Modify the Registered Loggers

Retrieve the registered loggers

To get all registered loggers, you could use the code: Collection<Logger> loggers = loggerManager.getLoggers();

Get the log level of a package

To retrieve the log level for the package org.apache.solr.core.SolrCore, you could use: loggerManager.getLoggerLevel("org.apache.solr.core.SolrCore")

Set the log level for a package

To set the DEBUG level for the package org.apache.solr.core.SolrCore, you could use: loggerManager.setLoggerLevel("org.apache.solr.core.SolrCore", LogLevel.DEBUG)

Translate Logs

To be able to provide a translation key for logging, you could use the SLF4J Marker interface which allows logging listeners that receive logging events.  These ones will use a localization framework that will convert the translation key to the translated version.


// Log producer
logger.error(new TranslationMarker("myapplication.error"), "An error has occurred");
// Log displayer

#set($translatedLogEvent = $services.logging.translate($logEvent))

Organize a Set of Logs as a Tree

You can organize a set of logs as a tree by using the following LogEvent markers:

  • public static final Marker MARKER_BEGIN = MarkerFactory.getMarker("xwiki.begin");
  • public static final Marker MARKER_END = MarkerFactory.getMarker("xwiki.end");
logger.info(LogEvent.MARKER_BEGIN, "Start the task");
logger.error("Failed execute part of the task");
logger.info(LogEvent.MARKER_END, "Task is finished but failed");

logger.info(LogEvent.MARKER_BEGIN, "Start a new task");
logger.info(LogEvent.MARKER_END, "Task successfully finished");

You can also use LogTree in order to interpret such a log and get helpers to navigate into the tree.

The logging script service also provide a helper to convert a log list into a tree: #set($logtree = $services.logging.toLogTree($logs))


Related Pages

Trying to decide between Cloud and On Premise? See the comparison on the XWiki Help Center.

Search this space