incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r886719 - in /websites/staging/sling/trunk/content: ./ documentation/development/logging-new.html documentation/development/sling-log-support.png
Date Fri, 15 Nov 2013 11:09:11 GMT
Author: buildbot
Date: Fri Nov 15 11:09:11 2013
New Revision: 886719

Log:
Staging update by buildbot for sling

Added:
    websites/staging/sling/trunk/content/documentation/development/logging-new.html
    websites/staging/sling/trunk/content/documentation/development/sling-log-support.png 
 (with props)
Modified:
    websites/staging/sling/trunk/content/   (props changed)

Propchange: websites/staging/sling/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Fri Nov 15 11:09:11 2013
@@ -1 +1 @@
-1541796
+1542230

Added: websites/staging/sling/trunk/content/documentation/development/logging-new.html
==============================================================================
--- websites/staging/sling/trunk/content/documentation/development/logging-new.html (added)
+++ websites/staging/sling/trunk/content/documentation/development/logging-new.html Fri Nov
15 11:09:11 2013
@@ -0,0 +1,359 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE- 2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+  <head>
+    <title>Apache Sling - Logging</title>
+    <link rel="icon" href="/res/favicon.ico">
+    <link rel="stylesheet" href="/res/site.css" type="text/css" media="all">
+    <link rel="stylesheet" href="/res/codehilite.css" type="text/css" media="all">
+    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+  </head>
+  <body>
+    <div class="title">
+      <div class="logo">
+        <a href="http://sling.apache.org/">
+          <img border="0" alt="Apache Sling" src="/res/logo.png">
+        </a>
+      </div>
+      <div class="header">
+        <a href="http://www.apache.org/">
+          <img border="0" alt="Apache" src="/res/apache.png">
+        </a>
+      </div>
+    </div>
+    
+    <div class="menu"> 
+      <p><strong><a href="/documentation.html">Documentation</a></strong>
<br />
+<a href="/documentation/getting-started.html">Getting Started</a> <br />
+<a href="/documentation/the-sling-engine.html">The Sling Engine</a> <br />
+<a href="/documentation/development.html">Development</a> <br />
+<a href="/documentation/bundles.html">Bundles</a> <br />
+<a href="/documentation/tutorials-how-tos.html">Tutorials &amp; How-Tos</a>
<br />
+<a href="/documentation/configuration.html">Configuration</a> <br />
+<a href="http://s.apache.org/sling.wiki">Wiki</a> <br />
+<a href="http://s.apache.org/sling.faq">FAQ</a> <br />
+<a href="/sitemap.html">Site Map</a></p>
+<p><strong>API Docs</strong>  <br />
+<a href="/apidocs/sling6/index.html">Sling 6</a> <br />
+<a href="/apidocs/sling5/index.html">Sling 5</a>   </p>
+<p><strong>Project info</strong> <br />
+<a href="/downloads.cgi">Downloads</a> <br />
+<a href="http://www.apache.org/licenses/">License</a> <br />
+<a href="/contributing.html">Contributing</a> <br />
+<a href="/news.html">News</a> <br />
+<a href="/links.html">Links</a> <br />
+<a href="/project-information.html">Project Information</a> <br />
+<a href="https://issues.apache.org/jira/browse/SLING">Issue Tracker</a> <br
/>
+<a href="http://svn.apache.org/viewvc/sling/trunk">Browse Source Repository</a>
<br />
+<a href="/project-information/security.html">Security</a>   </p>
+<p><strong>Sponsorship</strong> <br />
+<a href="http://www.apache.org/foundation/thanks.html">Thanks</a> <br />
+<a href="http://www.apache.org/foundation/sponsorship.html">Become a Sponsor</a>
<br />
+<a href="http://www.apache.org/foundation/buy_stuff.html">Buy Stuff</a>   </p>
+<!-- no valid ads for now, we'll  reactivate this when needed
+<iframe 
+    src="http://www.apache.org/ads/button.html"
+    style="border-width:0; float: left" frameborder="0" 
+    scrolling="no"
+    width="135" 
+    height="135">
+</iframe>
+-->
+    </div>
+    
+    <div class="main">
+      <div class="breadcrump" style="font-size: 80%;">
+        <a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/documentation.html">Documentation</a>&nbsp;&raquo&nbsp;<a
href="/documentation/development.html">Development</a>
+      </div>
+
+      
+      
+      <h1>Logging</h1>
+      <div class="note">
+Work in progress as part of SLING-3070
+</div>
+
+<div class="note">
+This document is for new 4.x release of Sling Commons Log components. For older version refer
to
+</div>
+
+<h2 id="introduction">Introduction</h2>
+<p>Logging in Sling is supported by the <code>org.apache.sling.commons.log</code>
bundle, which is one of the first bundles installed
+and started by the Sling Launcher. This bundle along with other bundles manage the Sling
Logging and provide following
+features</p>
+<ul>
+<li>Implements the OSGi Log Service Specification and registers the <code>LogService</code>
and <code>LogReader</code> services</li>
+<li>Exports three commonly used logging APIs:</li>
+<li><a href="http://www.slf4j.org">Simple Logging Facade for Java (SLF4J)</a></li>
+<li><a href="http://jakarta.apache.org/commons/logging">Apache Commons Logging</a></li>
+<li><a href="http://logging.apache.org/log4j/index.html">log4j</a></li>
+<li><a href="http://download.oracle.com/javase/6/docs/api/java/util/logging/package-summary.html">java.util.logging</a></li>
+<li>Configures logging through Logback which is integrated with the OSGi environment</li>
+</ul>
+<h2 id="logback-integration">Logback Integration</h2>
+<p>Logback integration provides following features</p>
+<ul>
+<li>LogBack configuration can be provided via Logback config xml</li>
+<li>Supports Appenders registered as OSGi Services</li>
+<li>Supports Filters and TurboFilters registered as OSGi Services</li>
+<li>Support providing Logback config as fragments through OSGi Service Registry</li>
+<li>Support for referring to Appenders registered as OSGi services from with Logback
+  config</li>
+<li>Exposing Logback runtime state through Felix WebConsole Plugin</li>
+</ul>
+<p>Following sections would provide more details around these features</p>
+<h3 id="turbofilters-as-osgi-service">TurboFilters as OSGi Service</h3>
+<p><a href="http://logback.qos.ch/manual/filters.html#TurboFilter">Logback TurboFilter</a>
operate globally and invoked for every Logback call. To register a <code>TurboFilter</code>
as OSGi service
+the bundle just need to register a service  against <code>ch.qos.logback.classic.turbo.TurboFilter</code>
class</p>
+<div class="codehilite"><pre><span class="n">import</span> <span
class="n">import</span> <span class="n">ch</span><span class="p">.</span><span
class="n">qos</span><span class="p">.</span><span class="n">logback</span><span
class="p">.</span><span class="n">classic</span><span class="p">.</span><span
class="n">turbo</span><span class="p">.</span><span class="n">MatchingFilter</span><span
class="p">;</span>
+
+<span class="n">SimpleTurboFilter</span> <span class="n">stf</span>
<span class="p">=</span> <span class="n">new</span> <span class="n">SimpleTurboFilter</span><span
class="p">();</span>
+<span class="n">ServiceRegistration</span> <span class="n">sr</span>
 <span class="p">=</span> <span class="n">bundleContext</span><span
class="p">.</span><span class="n">registerService</span><span class="p">(</span><span
class="n">TurboFilter</span><span class="p">.</span><span class="n">class</span><span
class="p">.</span><span class="n">getName</span><span class="p">(),</span>
<span class="n">stf</span><span class="p">,</span> <span class="n">null</span><span
class="p">);</span>
+
+<span class="n">private</span> <span class="n">static</span> <span
class="n">class</span> <span class="n">SimpleTurboFilter</span> <span
class="n">extends</span> <span class="n">MatchingFilter</span> <span
class="p">{</span>
+    <span class="p">@</span><span class="n">Override</span>
+    <span class="n">public</span> <span class="n">FilterReply</span>
<span class="n">decide</span><span class="p">(</span><span class="n">Marker</span>
<span class="n">marker</span><span class="p">,</span> <span class="n">Logger</span>
<span class="n">logger</span><span class="p">,</span> <span class="n">Level</span>
<span class="n">level</span><span class="p">,</span> <span class="n">String</span>
<span class="n">format</span><span class="p">,</span>
+     <span class="n">Object</span><span class="p">[]</span> <span
class="n">params</span><span class="p">,</span> <span class="n">Throwable</span>
<span class="n">t</span><span class="p">)</span> <span class="p">{</span>
+        <span class="k">if</span><span class="p">(</span><span
class="n">logger</span><span class="p">.</span><span class="n">getName</span><span
class="p">().</span><span class="n">equals</span><span class="p">(</span>&quot;<span
class="n">turbofilter</span><span class="p">.</span><span class="n">foo</span><span
class="p">.</span><span class="n">bar</span>&quot;<span class="p">)){</span>
+                <span class="k">return</span> <span class="n">FilterReply</span><span
class="p">.</span><span class="n">DENY</span><span class="p">;</span>
+        <span class="p">}</span>
+        <span class="k">return</span> <span class="n">FilterReply</span><span
class="p">.</span><span class="n">NEUTRAL</span><span class="p">;</span>
+    <span class="p">}</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>As these filters are invoked for every call they must not take much time to execute.</p>
+<h3 id="filter-as-osgi-service">Filter as OSGi service</h3>
+<p><a href="http://logback.qos.ch/manual/filters.html">Logback Filters</a>
are attached to appenders and are used to determine if any LoggingEvent needs to
+be passed to the appender. When registering a filter the bundle needs to configure a service
property
+<code>appenders</code> which refers to list of appender names to which the Filter
must be attached</p>
+<div class="codehilite"><pre><span class="n">import</span> <span
class="n">ch</span><span class="p">.</span><span class="n">qos</span><span
class="p">.</span><span class="n">logback</span><span class="p">.</span><span
class="n">core</span><span class="p">.</span><span class="n">filter</span><span
class="p">.</span><span class="n">Filter</span><span class="p">;</span>
+
+<span class="n">SimpleFilter</span> <span class="n">stf</span> <span
class="p">=</span> <span class="n">new</span> <span class="n">SimpleFilter</span><span
class="p">();</span>
+<span class="n">Dictionary</span><span class="o">&lt;</span><span
class="n">String</span><span class="p">,</span> <span class="n">Object</span><span
class="o">&gt;</span> <span class="n">props</span> <span class="p">=</span>
<span class="n">new</span> <span class="n">Hashtable</span><span
class="o">&lt;</span><span class="n">String</span><span class="p">,</span>
<span class="n">Object</span><span class="o">&gt;</span><span
class="p">();</span>
+<span class="n">props</span><span class="p">.</span><span class="n">put</span><span
class="p">(</span>&quot;<span class="n">appenders</span>&quot;<span
class="p">,</span> &quot;<span class="n">TestAppender</span>&quot;<span
class="p">);</span>
+<span class="n">ServiceRegistration</span> <span class="n">sr</span>
 <span class="p">=</span> <span class="n">bundleContext</span><span
class="p">.</span><span class="n">registerService</span><span class="p">(</span><span
class="n">Filter</span><span class="p">.</span><span class="n">class</span><span
class="p">.</span><span class="n">getName</span><span class="p">(),</span>
<span class="n">stf</span><span class="p">,</span> <span class="n">props</span><span
class="p">);</span>
+
+<span class="n">private</span> <span class="n">static</span> <span
class="n">class</span> <span class="n">SimpleFilter</span> <span class="n">extends</span>
<span class="n">Filter</span><span class="o">&lt;</span><span
class="n">ILoggingEvent</span><span class="o">&gt;</span> <span
class="p">{</span>
+
+    <span class="p">@</span><span class="n">Override</span>
+    <span class="n">public</span> <span class="n">FilterReply</span>
<span class="n">decide</span><span class="p">(</span><span class="n">ILoggingEvent</span>
<span class="n">event</span><span class="p">)</span> <span class="p">{</span>
+        <span class="k">if</span><span class="p">(</span><span
class="n">event</span><span class="p">.</span><span class="n">getLoggerName</span><span
class="p">().</span><span class="n">equals</span><span class="p">(</span>&quot;<span
class="n">filter</span><span class="p">.</span><span class="n">foo</span><span
class="p">.</span><span class="n">bar</span>&quot;<span class="p">)){</span>
+            <span class="k">return</span> <span class="n">FilterReply</span><span
class="p">.</span><span class="n">DENY</span><span class="p">;</span>
+        <span class="p">}</span>
+        <span class="k">return</span> <span class="n">FilterReply</span><span
class="p">.</span><span class="n">NEUTRAL</span><span class="p">;</span>
+    <span class="p">}</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<h3 id="appenders-as-osgi-service">Appenders as OSGi service</h3>
+<p><a href="http://logback.qos.ch/manual/appenders.html">Logback Appenders</a>
handle the logging events produced by Logback. To register an <code>Appender</code>
as OSGi service
+the bundle just need to register a service  against <code>ch.qos.logback.core.Appender</code>
class.  When registering an
+appender the bundle needs to configure a service property <code>loggers</code>
which refers to list of logger names to which
+the Appender must be attached</p>
+<div class="codehilite"><pre><span class="n">Dictionary</span><span
class="o">&lt;</span><span class="n">String</span><span class="p">,</span><span
class="n">Object</span><span class="o">&gt;</span> <span class="n">props</span>
<span class="p">=</span> <span class="n">new</span> <span class="n">Hashtable</span><span
class="o">&lt;</span><span class="n">String</span><span class="p">,</span>
<span class="n">Object</span><span class="o">&gt;</span><span
class="p">();</span>
+
+<span class="n">String</span><span class="p">[]</span> <span class="n">loggers</span>
<span class="p">=</span> <span class="p">{</span>
+        &quot;<span class="n">foo</span><span class="p">.</span><span
class="n">bar</span><span class="p">:</span><span class="n">DEBUG</span>&quot;<span
class="p">,</span>
+        &quot;<span class="n">foo</span><span class="p">.</span><span
class="n">bar</span><span class="p">.</span><span class="n">zoo</span><span
class="p">:</span><span class="n">INFO</span>&quot;<span class="p">,</span>
+<span class="p">};</span>
+
+<span class="n">props</span><span class="p">.</span><span class="n">put</span><span
class="p">(</span>&quot;<span class="n">loggers</span>&quot;<span
class="p">,</span><span class="n">loggers</span><span class="p">);</span>
+<span class="n">sr</span> <span class="p">=</span> <span class="n">bundleContext</span><span
class="p">.</span><span class="n">registerService</span><span class="p">(</span><span
class="n">Appender</span><span class="p">.</span><span class="n">class</span><span
class="p">.</span><span class="n">getName</span><span class="p">(),</span><span
class="n">this</span><span class="p">,</span><span class="n">props</span><span
class="p">);</span>
+</pre></div>
+
+
+<h3 id="logback-config-fragment-support">Logback Config Fragment Support</h3>
+<p>Logback supports including parts of a configuration file from another file (See
<a href="http://logback.qos.ch/manual/configuration.html#fileInclusion">File Inclusion</a>).
This module
+extends that support by allowing other bundles to provide config fragments. There are two
ways to achieve that</p>
+<h4 id="exposing-fragment-as-string-objects">Exposing fragment as String objects</h4>
+<p>If you have the config as string then you can register that String instance as a
service with property <code>logbackConfig</code>
+set to true. Sling Logback Extension would monitor such objects and pass them to logback</p>
+<div class="codehilite"><pre>Properties props = new Properties();
+props.setProperty(&quot;logbackConfig&quot;,&quot;true&quot;);
+
+String config = &quot;<span class="nt">&lt;included&gt;</span>\n&quot;
+
+        &quot;  <span class="nt">&lt;appender</span> <span class="na">name=</span><span
class="s">\&quot;FOOFILE\&quot;</span> <span class="na">class=</span><span
class="s">\&quot;ch.qos.logback.core.FileAppender\&quot;</span><span class="nt">&gt;</span>\n&quot;
+
+        &quot;    <span class="nt">&lt;file&gt;</span><span class="cp">${</span><span
class="n">sling</span><span class="o">.</span><span class="n">home</span><span
class="cp">}</span>/logs/foo.log<span class="nt">&lt;/file&gt;</span>\n&quot;
+
+        &quot;    <span class="nt">&lt;encoder&gt;</span>\n&quot;
+
+        &quot;      <span class="nt">&lt;pattern&gt;</span>%d %-5level
%logger{35} - %msg %n<span class="nt">&lt;/pattern&gt;</span>\n&quot;
+
+        &quot;    <span class="nt">&lt;/encoder&gt;</span>\n&quot;
+
+        &quot;  <span class="nt">&lt;/appender&gt;</span>\n&quot;
+
+        &quot;\n&quot; +
+        &quot;  <span class="nt">&lt;logger</span> <span class="na">name=</span><span
class="s">\&quot;foo.bar.include\&quot;</span> <span class="na">level=</span><span
class="s">\&quot;INFO\&quot;</span><span class="nt">&gt;</span>\n&quot;
+
+        &quot;       <span class="nt">&lt;appender</span><span class="err">-ref</span>
<span class="na">ref=</span><span class="s">\&quot;FOOFILE\&quot;</span>
<span class="nt">/&gt;</span>\n&quot; +
+        &quot;  <span class="nt">&lt;/logger&gt;</span>\n&quot;
+
+        &quot;\n&quot; +
+        &quot;<span class="nt">&lt;/included&gt;</span>&quot;;
+
+registration = context.registerService(String.class.getName(),config,props);
+</pre></div>
+
+
+<p>If the config needs to be updated just re-register the service and change would
be picked up</p>
+<h4 id="exposing-fragment-as-configprovider-instance">Exposing fragment as ConfigProvider
instance</h4>
+<p>Another way to provide config fragment is by providing an implementation of <code>org.apache.sling.commons.log.logback.ConfigProvider</code></p>
+<div class="codehilite"><pre><span class="p">@</span><span class="n">Component</span>
+<span class="p">@</span><span class="n">Service</span>
+<span class="n">public</span> <span class="n">class</span> <span
class="n">ConfigProviderExample</span> <span class="n">implements</span>
<span class="n">ConfigProvider</span> <span class="p">{</span>
+    <span class="n">public</span> <span class="n">InputSource</span>
<span class="n">getConfigSource</span><span class="p">()</span> <span
class="p">{</span>
+        <span class="k">return</span> <span class="n">new</span>
<span class="n">InputSource</span><span class="p">(</span><span
class="n">getClass</span><span class="p">().</span><span class="n">getClassLoader</span><span
class="p">().</span><span class="n">getResourceAsStream</span><span
class="p">(</span>&quot;<span class="n">foo</span><span class="o">-</span><span
class="n">config</span><span class="p">.</span><span class="n">xml</span>&quot;<span
class="p">));</span>
+    <span class="p">}</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>If the config changes then sending an event to <code>org/apache/sling/commons/log/RESET</code>
would reset the listener</p>
+<div class="codehilite"><pre><span class="n">eventAdmin</span><span
class="p">.</span><span class="n">sendEvent</span><span class="p">(</span><span
class="n">new</span> <span class="n">Event</span><span class="p">(</span>&quot;<span
class="n">org</span><span class="o">/</span><span class="n">apache</span><span
class="o">/</span><span class="n">sling</span><span class="o">/</span><span
class="n">commons</span><span class="o">/</span><span class="nb">log</span><span
class="o">/</span><span class="n">RESET</span>&quot;<span class="p">,</span><span
class="n">new</span> <span class="n">Properties</span><span class="p">()));</span>
+</pre></div>
+
+
+<h3 id="external-config-file">External Config File</h3>
+<p>Logback can be configured with an external file. The file name can be specified
through</p>
+<ol>
+<li>OSGi config - Look for config with name <code>Apache Sling Logging Configuration</code>
and specify the path for
+   config file property</li>
+<li>OSGi Framework Properties - Logback supports also looks for file name with property
name
+   <code>org.apache.sling.commons.log.configurationFile</code></li>
+</ol>
+<p>If you are providing an external config file then to support OSGi integration you
would need to add following
+action entry</p>
+<div class="codehilite"><pre><span class="o">&lt;</span><span
class="n">newRule</span> <span class="n">pattern</span><span class="p">=</span>&quot;<span
class="o">*/</span><span class="n">configuration</span><span class="o">/</span><span
class="n">osgi</span>&quot;
+         <span class="n">actionClass</span><span class="p">=</span>&quot;<span
class="n">org</span><span class="p">.</span><span class="n">apache</span><span
class="p">.</span><span class="n">sling</span><span class="p">.</span><span
class="n">commons</span><span class="p">.</span><span class="nb">log</span><span
class="p">.</span><span class="n">logback</span><span class="p">.</span><span
class="n">OsgiAction</span>&quot;<span class="o">/&gt;</span>
+<span class="o">&lt;</span><span class="n">newRule</span> <span
class="n">pattern</span><span class="p">=</span>&quot;<span class="o">*/</span><span
class="n">configuration</span><span class="o">/</span><span class="n">appender</span><span
class="o">-</span><span class="n">ref</span><span class="o">-</span><span
class="n">osgi</span>&quot;
+         <span class="n">actionClass</span><span class="p">=</span>&quot;<span
class="n">org</span><span class="p">.</span><span class="n">apache</span><span
class="p">.</span><span class="n">sling</span><span class="p">.</span><span
class="n">commons</span><span class="p">.</span><span class="nb">log</span><span
class="p">.</span><span class="n">logback</span><span class="p">.</span><span
class="n">OsgiAppenderRefAction</span>&quot;<span class="o">/&gt;</span>
+<span class="o">&lt;</span><span class="n">osgi</span><span
class="o">/&gt;</span>
+</pre></div>
+
+
+<p>The <code>osgi</code> element enables the OSGi integration support</p>
+<h3 id="java-util-logging-jul-integration">Java Util Logging (JUL) Integration</h3>
+<p>The bundle also support <a href="http://www.slf4j.org/api/org/slf4j/bridge/SLF4JBridgeHandler.html">SLF4JBridgeHandler</a>.
To enable JUL integration following two steps
+needs to be done. This features allows routing logging messages from JUL to the Logbback
appenders</p>
+<ol>
+<li>Set framework property <code>org.apache.sling.commons.log.julenabled</code>
to true</li>
+<li>
+<p>Set the <a href="http://logback.qos.ch/manual/configuration.html#LevelChangePropagator">LevelChangePropagator</a>
in LogbackConfig</p>
+<div class="codehilite"><pre><span class="nt">&lt;configuration&gt;</span>
+    <span class="nt">&lt;contextListener</span> <span class="na">class=</span><span
class="s">&quot;ch.qos.logback.classic.jul.LevelChangePropagator&quot;</span><span
class="nt">/&gt;</span>
+    ...
+<span class="nt">&lt;/configuration&gt;</span>
+</pre></div>
+
+
+</li>
+</ol>
+<h3 id="configuring-osgi-based-appenders-in-logback-config">Configuring OSGi based
appenders in Logback Config</h3>
+<p>So far Sling used to configure the appenders based on OSGi config. That mode only
provide a very limited
+set to configuration options. To make use of other Logback features you can override the
OSGi config
+from within the Logback config file. OSGi config based appenders are named based on the file
name</p>
+<p>For example for following OSGi config</p>
+<div class="codehilite"><pre><span class="n">org</span><span class="p">.</span><span
class="n">apache</span><span class="p">.</span><span class="n">sling</span><span
class="p">.</span><span class="n">commons</span><span class="p">.</span><span
class="nb">log</span><span class="p">.</span><span class="n">file</span><span
class="p">=</span>&quot;<span class="n">logs</span><span class="o">/</span><span
class="n">error</span><span class="p">.</span><span class="nb">log</span>&quot;
+<span class="n">org</span><span class="p">.</span><span class="n">apache</span><span
class="p">.</span><span class="n">sling</span><span class="p">.</span><span
class="n">commons</span><span class="p">.</span><span class="nb">log</span><span
class="p">.</span><span class="n">level</span><span class="p">=</span>&quot;<span
class="n">info</span>&quot;
+<span class="n">org</span><span class="p">.</span><span class="n">apache</span><span
class="p">.</span><span class="n">sling</span><span class="p">.</span><span
class="n">commons</span><span class="p">.</span><span class="nb">log</span><span
class="p">.</span><span class="n">file</span><span class="p">.</span><span
class="nb">size</span><span class="p">=</span>&quot;<span class="s">&#39;.&#39;</span><span
class="n">yyyy</span><span class="o">-</span><span class="n">MM</span><span
class="o">-</span><span class="n">dd</span>&quot;
+<span class="n">org</span><span class="p">.</span><span class="n">apache</span><span
class="p">.</span><span class="n">sling</span><span class="p">.</span><span
class="n">commons</span><span class="p">.</span><span class="nb">log</span><span
class="p">.</span><span class="n">file</span><span class="p">.</span><span
class="n">number</span><span class="p">=</span><span class="n">I</span>&quot;7&quot;
+<span class="n">org</span><span class="p">.</span><span class="n">apache</span><span
class="p">.</span><span class="n">sling</span><span class="p">.</span><span
class="n">commons</span><span class="p">.</span><span class="nb">log</span><span
class="p">.</span><span class="n">pattern</span><span class="p">=</span>&quot;<span
class="p">{</span>0<span class="p">,</span><span class="n">date</span><span
class="p">,</span><span class="n">dd</span><span class="p">.</span><span
class="n">MM</span><span class="p">.</span><span class="n">yyyy</span>
<span class="n">HH</span><span class="p">:</span><span class="n">mm</span><span
class="p">:</span><span class="n">ss</span><span class="p">.</span><span
class="n">SSS</span><span class="p">}</span> <span class="o">*</span><span
class="p">{</span>4<span class="p">}</span><span class="o">*</span>
<span class="p">[{</span>2<span class="p">}]</span> <span class="p">{</span>3<span
class="p">}</span> <span class="p">{</span>5<span class="p">}</span>&quo
 t;
+</pre></div>
+
+
+<p>The Logback appender would be named as <code>logs/error.log</code>.
To extend/override the config in Logback config
+create an appender with name <code>logs/error.log</code></p>
+<div class="codehilite"><pre><span class="o">&lt;</span><span
class="s-Atom">appender</span> <span class="s-Atom">name=</span><span
class="s2">&quot;/logs/error.log&quot;</span> <span class="s-Atom">class=</span><span
class="s2">&quot;ch.qos.logback.core.FileAppender&quot;</span><span class="o">&gt;</span>
+  <span class="o">&lt;</span><span class="s-Atom">file&gt;</span><span
class="err">$</span><span class="p">{</span><span class="s-Atom">sling</span><span
class="p">.</span><span class="s-Atom">home</span><span class="p">}</span><span
class="o">/</span><span class="s-Atom">logs</span><span class="o">/</span><span
class="s-Atom">error</span><span class="p">.</span><span class="s-Atom">log&lt;/file</span><span
class="o">&gt;</span>
+  <span class="o">&lt;</span><span class="s-Atom">encoder</span><span
class="o">&gt;</span>
+    <span class="o">&lt;</span><span class="s-Atom">pattern&gt;</span><span
class="c1">%d %-5level %X{sling.userId:-NA} [%thread] %logger{30} %marker- %msg %n&lt;/pattern&gt;</span>
+    <span class="o">&lt;</span><span class="s-Atom">immediateFlush</span><span
class="o">&gt;</span><span class="s-Atom">true&lt;/immediateFlush</span><span
class="o">&gt;</span>
+  <span class="s-Atom">&lt;/encoder</span><span class="o">&gt;</span>
+<span class="s-Atom">&lt;/appender</span><span class="o">&gt;</span>
+</pre></div>
+
+
+<p>In this case then Log module would create appender based on Logback config instead
of OSGi config. This can
+be used to move the application from OSGi based config to Logback based config easily</p>
+<h2 id="initial-configuration">Initial Configuration</h2>
+<p>The <code>org.apache.sling.commons.log</code> bundle gets the initial
configuration from the following <code>BundleContext</code> properties:</p>
+<table>
+<thead>
+<tr>
+<th>Property</th>
+<th>Default</th>
+<th>Description</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td><code>org.apache.sling.commons.log.level</code></td>
+<td><code>INFO</code></td>
+<td>Sets the initial logging level of the root logger. This may be any of the defined
logging levels <code>DEBUG</code>, <code>INFO</code>, <code>WARN</code>,
<code>ERROR</code> and <code>FATAL</code>.</td>
+</tr>
+<tr>
+<td><code>org.apache.sling.commons.log.file</code></td>
+<td>undefined</td>
+<td>Sets the log file to which log messages are written. If this property is empty
or missing, log messages are written to <code>System.out</code>.</td>
+</tr>
+<tr>
+<td><code>org.apache.sling.commons.log.file.number</code></td>
+<td>5</td>
+<td>The number of rotated files to keep.</td>
+</tr>
+<tr>
+<td><code>org.apache.sling.commons.log.file.size</code></td>
+<td>'.'yyyy-MM-dd</td>
+<td>Defines how the log file is rotated (by schedule or by size) and when to rotate.
See the section <em>Log File Rotation</em> below for full details on log file
rotation.</td>
+</tr>
+<tr>
+<td><code>org.apache.sling.commons.log.pattern</code></td>
+<td>{0,date,dd.MM.yyyy HH:mm:ss.SSS} *{4}* [{2}]() {3} {5}</td>
+<td>The <code>MessageFormat</code> pattern to use for formatting log messages
with the root logger.</td>
+</tr>
+<tr>
+<td><code>org.apache.sling.commons.log.julenabled</code></td>
+<td>n/a</td>
+<td>Enables the <code>java.util.logging</code> support.</td>
+</tr>
+<tr>
+<td><code>org.apache.sling.commons.log.configurationFile</code></td>
+<td>n/a</td>
+<td>Path for the Logback config file which would be used to configure logging. If the
path is not absolute then it would be resolved against Sling Home</td>
+</tr>
+</tbody>
+</table>
+<h2 id="webconsole-plugin-enhancements">WebConsole Plugin enhancements</h2>
+<p>The web Console Plugin supports following features</p>
+<ul>
+<li>Displays list of loggers which have level or appender configured</li>
+<li>List of File appenders with location of current active files</li>
+<li>Content of LogBack config file</li>
+<li>Content of various Logback config fragment</li>
+<li>Logback Status logs</li>
+</ul>
+<p><img src="sling-log-support.png" /></p>
+      <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
+        Rev. 1542230 by chetanm on Fri, 15 Nov 2013 11:09:02 +0000
+      </div>
+      <div class="trademarkFooter"> 
+        Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project
+        logo are trademarks of The Apache Software Foundation. All other marks mentioned
+        may be trademarks or registered trademarks of their respective owners.
+      </div>
+    </div>
+  </body>
+</html>

Added: websites/staging/sling/trunk/content/documentation/development/sling-log-support.png
==============================================================================
Binary file - no diff available.

Propchange: websites/staging/sling/trunk/content/documentation/development/sling-log-support.png
------------------------------------------------------------------------------
    svn:mime-type = image/png



Mime
View raw message