Apache Sling Logback Groovy Fragment

Clone this repo:


  1. 7af744b SLING-12094 - Use GitHub for the Maven scm.url value by Robert Munteanu · 7 months ago master
  2. ca0770b SLING-11709 - Set up Jira autolinks to all Sling Github projects by Robert Munteanu · 1 year, 2 months ago
  3. c6e01be SLING-10676 - remove SECURITY.md which is not needed by Bertrand Delacretaz · 2 years, 10 months ago
  4. 74826ef SLING-10676 - add or update SECURITY.md by Bertrand Delacretaz · 2 years, 10 months ago
  5. 8c0f314 SLING-10676 - add or update SECURITY.md by Bertrand Delacretaz · 2 years, 10 months ago

Apache Sling

Build Status Sonarcloud Status Contrib License

Apache Sling Logback Groovy Fragment

This module is part of the Apache Sling project.

This fragment is required to make use of Groovy based event evaluation support provided by Logback. This enables programatic filtering of the log messages and is useful to get desired logs without flooding the system. For example Oak logs the JCR operations being performed via a particular session. if this lo is enabled it would flood the log with messages from all the active session. However if you need logging only from session created in a particular thread then that can be done in following way

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="1 second">
  <newRule pattern="*/configuration/osgi" actionClass="org.apache.sling.commons.log.logback.OsgiAction"/>
  <newRule pattern="*/configuration/appender-ref-osgi" actionClass="org.apache.sling.commons.log.logback.OsgiAppenderRefAction"/>

   <appender name="OAK" class="ch.qos.logback.core.FileAppender">
    <filter class="ch.qos.logback.core.filter.EvaluatorFilter">      
      <evaluator class="ch.qos.logback.classic.boolex.GEventEvaluator"> 
            return e.getThreadName().contains("JobHandler");
      <pattern>%d %-5level [%thread] %marker- %msg %n</pattern> 

  <logger name="org.apache.jackrabbit.oak.jcr.operations" level="DEBUG" additivity="false">
      <appender-ref ref="OAK"/>

Logback exposes a variable e which is of type ILoggingEvent. It provides access to current logging event. Above logback config would route all log messages from org.apache.jackrabbit.oak.jcr.operations category to ${sling.home}/logs/oak.log. Further only those log messages would be logged where the threadName contains JobHandler. Depending on the requirement the expression can be customised.