[logback-dev] svn commit: r2100 - in logback/trunk: logback-access/src/main/java/ch/qos/logback/access/sift logback-access/src/test/input/jetty logback-core/src/main/java/ch/qos/logback/core/joran/action logback-examples/src/main/java/chapter4/sift logback-site/src/site/pages/manual

noreply.ceki at qos.ch noreply.ceki at qos.ch
Tue Dec 23 22:22:25 CET 2008


Author: ceki
Date: Tue Dec 23 22:22:24 2008
New Revision: 2100

Added:
   logback/trunk/logback-examples/src/main/java/chapter4/sift/access-siftingFile.xml
Removed:
   logback/trunk/logback-access/src/test/input/jetty/siftingFile.xml
Modified:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/sift/AccessEventDiscriminator.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AppenderRefAction.java
   logback/trunk/logback-site/src/site/pages/manual/appenders.html

Log:
- improved docs

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/sift/AccessEventDiscriminator.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/sift/AccessEventDiscriminator.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/sift/AccessEventDiscriminator.java	Tue Dec 23 22:22:24 2008
@@ -38,7 +38,9 @@
    * REQUEST_ATTRIBUTE, SESSION_ATTRIBUTE, REMOTE_ADDRESS,
    * LOCAL_PORT,REQUEST_URI
    * 
-   * <p> The first three fields require an additional key.
+   * <p> The first three fields require an additional key. For the
+   * SESSION_ATTRIBUTE field, the additional key named "id" has special meaning
+   * as it is mapped to the session id of the current http request.
    */
   public enum FieldName {
     COOKIE, REQUEST_ATTRIBUTE, SESSION_ATTRIBUTE, REMOTE_ADDRESS, LOCAL_PORT, REQUEST_URI
@@ -61,16 +63,19 @@
   public String getRawDiscriminatingValue(AccessEvent acccessEvent) {
     switch (fieldName) {
     case COOKIE:
+      // tested
       return acccessEvent.getCookie(additionalKey);
     case LOCAL_PORT:
       return String.valueOf(acccessEvent.getLocalPort());
     case REQUEST_ATTRIBUTE:
+      // tested
       return getRequestAttribute(acccessEvent);
     case SESSION_ATTRIBUTE:
       return getSessionAttribute(acccessEvent);
     case REMOTE_ADDRESS:
       return acccessEvent.getRemoteAddr();
     case REQUEST_URI:
+      // tested
       return getRequestURI(acccessEvent);
     default:
       return null;
@@ -79,13 +84,13 @@
 
   private String getRequestAttribute(AccessEvent acccessEvent) {
     String attr = acccessEvent.getAttribute(additionalKey);
-    if(AccessEvent.NA.equals(attr)) {
+    if (AccessEvent.NA.equals(attr)) {
       return null;
     } else {
       return attr;
     }
   }
-  
+
   private String getRequestURI(AccessEvent acccessEvent) {
     String uri = acccessEvent.getRequestURI();
     if (uri != null && uri.length() >= 1 && uri.charAt(0) == '/') {
@@ -97,18 +102,9 @@
 
   private String getSessionAttribute(AccessEvent acccessEvent) {
     HttpServletRequest req = acccessEvent.getRequest();
-    System.out.println("req=" + req);
     if (req != null) {
       HttpSession session = req.getSession(false);
-      System.out.println("session=" + session);
       if (session != null) {
-        Enumeration ee = session.getAttributeNames();
-        while(ee.hasMoreElements()) {
-          String k = (String) ee.nextElement();
-          Object v = session.getAttribute(k);
-          System.out.println("Session "+k+"="+v);
-        }
-
         if ("id".equalsIgnoreCase(additionalKey)) {
           return session.getId();
         } else {

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AppenderRefAction.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AppenderRefAction.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AppenderRefAction.java	Tue Dec 23 22:22:24 2008
@@ -1,7 +1,7 @@
 /**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
+ * Logback: the generic, reliable, fast and flexible logging framework.
  * 
- * Copyright (C) 1999-2006, QOS.ch
+ * Copyright (C) 2000-2008, QOS.ch
  * 
  * This library is free software, you can redistribute it and/or modify it under
  * the terms of the GNU Lesser General Public License as published by the Free

Added: logback/trunk/logback-examples/src/main/java/chapter4/sift/access-siftingFile.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/sift/access-siftingFile.xml	Tue Dec 23 22:22:24 2008
@@ -0,0 +1,22 @@
+<configuration>
+
+  <appender name="SIFTING"
+    class="ch.qos.logback.access.sift.SiftingAppender">
+    <Discriminator>
+      <Key>id</Key>
+      <FieldName>SESSION_ATTRIBUTE</FieldName>
+      <AdditionalKey>username</AdditionalKey>
+      <DefaultValue>NA</DefaultValue>
+    </Discriminator>
+    <sift>
+      <appender name="${id}" class="ch.qos.logback.core.FileAppender">
+        <File>byUser/${id}.log</File>
+        <layout class="ch.qos.logback.access.PatternLayout">
+          <Pattern>%h %l %u %t \"%r\" %s %b</Pattern>
+        </layout>
+      </appender>
+    </sift>
+  </appender>
+
+  <appender-ref ref="SIFTING" />
+</configuration>
\ No newline at end of file

Modified: logback/trunk/logback-site/src/site/pages/manual/appenders.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/manual/appenders.html	(original)
+++ logback/trunk/logback-site/src/site/pages/manual/appenders.html	Tue Dec 23 22:22:24 2008
@@ -3512,11 +3512,47 @@
 
     <p>The desginated AccessEvent field can be one of COOKIE,
     REQUEST_ATTRIBUTE, SESSION_ATTRIBUTE, REMOTE_ADDRESS, LOCAL_PORT,
-    REQUEST_URI. Note that the fiest three fields require that the
-    <span class="option">AdditionalKey</span> property to be
+    REQUEST_URI. Note that the first three fields require that the
+    <span class="option">AdditionalKey</span> property also to be
     specified.</p>
     
+    <p>Below is an example configuration file.</p>
 
+    <em>Example 4.<span class="autoEx"/>: SiftingAppender configuration (logback-examples/src/main/java/chapter4/conf/sift/access-siftingFile.xml)</em>		
+    
+    <p class="source">&lt;configuration>
+  &lt;appender name="SIFTING" class="ch.qos.logback.access.sift.SiftingAppender">
+    &lt;Discriminator class="ch.qos.logback.access.sift.AccessEventDiscriminator">
+      &lt;Key>id&lt;/Key>
+      &lt;FieldName>SESSION_ATTRIBUTE&lt;/FieldName>
+      &lt;AdditionalKey>username&lt;/AdditionalKey>
+      &lt;DefaultValue>NA&lt;/DefaultValue>
+    &lt;/Discriminator>
+    &lt;sift>
+       &lt;appender name="${id}" class="ch.qos.logback.core.FileAppender">
+        &lt;File>byUser/${id}.log&lt;/File>
+        &lt;layout class="ch.qos.logback.access.PatternLayout">
+          &lt;Pattern>%h %l %u %t \"%r\" %s %b&lt;/Pattern>
+        &lt;/layout>
+      &lt;/appender>
+    &lt;/sift>
+  &lt;/appender>
+  &lt;appender-ref ref="SIFTING" />
+&lt;/configuration></p>
+
+
+    <p>In the above configuration file, a <code>SiftingAppender</code>
+    nests <code>FileAppender</code> instances. The key "id" is
+    designated as a variable which will be availabe to the nested
+    <code>FileAppender</code> instances. The default discriminator,
+    namely <code>AccessEventDiscriminator</code>, will search for
+    "username" session attribute in each <code>AccessEvent</code>. If
+    no such attribute is available, then the default value "NA" will
+    be used.  Thus, assuming the session attribute named "username"
+    contains the username of each logged on user, there will be a log
+    file under the <em>byUser/</em> folder (of the current folder)
+    named after each user containing the access logs for that user.
+    </p>
 
 
     <script src="../templates/footer.js" type="text/javascript"></script>


More information about the logback-dev mailing list