[ 
https://issues.apache.org/jira/browse/SLING-3814?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Chetan Mehrotra updated SLING-3814:
-----------------------------------

    Attachment: 
org.apache.sling.extensions.logback-groovy-fragment-1.0.0-SNAPSHOT-src.zip

Attached is the Fragment Bundle pom which can probably be part of 
contrib/extensions.

*Usage Example*
Following example demonstrate usage of Groovy code to filter log event in Oak 
operations. Oak logs the operations being performed via JCR (add node, set 
property etc) via {{org.apache.jackrabbit.oak.jcr.operations}} logger. Setting 
it to debug level would cause lots of logs as JCR API is being used heavily in 
a running system. So in such cases we need logs from a particular thread only 
say the JobHandler thread. This can be done via following logback.xml

{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <jmxConfigurator/>
  <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"/>
  <osgi/>

   <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"> 
        <expression><![CDATA[
            return event.getThreadName().contains("JobHandler");
        ]]></expression>
      </evaluator>
      <OnMismatch>DENY</OnMismatch>
      <OnMatch>ACCEPT</OnMatch>
    </filter>
    <file>${sling.home}/logs/oak.log</file>
    <encoder>
      <pattern>%d %-5level [%thread] %marker- %msg %n</pattern> 
      <immediateFlush>true</immediateFlush>
    </encoder>
  </appender>

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

Here the logging event would only be logged if the thread name contains 
JobHandler

> Groovy fragment bundle for Common Log to support scriptable event evaluation
> ----------------------------------------------------------------------------
>
>                 Key: SLING-3814
>                 URL: https://issues.apache.org/jira/browse/SLING-3814
>             Project: Sling
>          Issue Type: New Feature
>          Components: Extensions
>            Reporter: Chetan Mehrotra
>            Assignee: Chetan Mehrotra
>         Attachments: 
> org.apache.sling.extensions.logback-groovy-fragment-1.0.0-SNAPSHOT-src.zip
>
>
> Logback provides support for scriptable event evaluation [1] where a script 
> can be used to determine if the given logging event must be logged or not. 
> This proves useful to get precise logs in a concurrent env. For this Logback 
> support
> * Janino - Allow writing Java Code and is faster compared to Groovy. Due to 
> [LOGBACK-1001|http://jira.qos.ch/browse/LOGBACK-1001] it cannot be used 
> currently
> * Groovy
> Commons Log bundle can have optional dependency on Groovy classes but that 
> would cause issues as Commons Log starts at level 1 and further for stability 
> of Logging system it would be preferable if it gets its own copy of Groovy 
> (via a fragement).
> This feature is mostly to be used for debugging issues
> [1] http://logback.qos.ch/manual/filters.html



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to