[logback-dev] svn commit: r2278 - in logback-demo/trunk: . src/etc src/main/java/ch/qos/logback/demo src/main/java/ch/qos/logback/demo/login src/main/resources src/main/resources/parts src/main/webapp

noreply.ceki at qos.ch noreply.ceki at qos.ch
Thu Jun 11 14:22:36 CEST 2009


Author: ceki
Date: Thu Jun 11 14:22:36 2009
New Revision: 2278

Added:
   logback-demo/trunk/src/main/resources/parts/sifting.xml
Modified:
   logback-demo/trunk/scenario.txt
   logback-demo/trunk/src/etc/logback-access.xml
   logback-demo/trunk/src/main/java/ch/qos/logback/demo/Constants.java
   logback-demo/trunk/src/main/java/ch/qos/logback/demo/ViewLastLog.java
   logback-demo/trunk/src/main/java/ch/qos/logback/demo/login/LoginAction.java
   logback-demo/trunk/src/main/java/ch/qos/logback/demo/login/LogoutAction.java
   logback-demo/trunk/src/main/resources/logback.xml
   logback-demo/trunk/src/main/webapp/viewStatii.jsp

Log:
- fixed display problem in Status servlet (via changes in viewStatii.jsp
- other improvements

Modified: logback-demo/trunk/scenario.txt
==============================================================================
--- logback-demo/trunk/scenario.txt	(original)
+++ logback-demo/trunk/scenario.txt	Thu Jun 11 14:22:36 2009
@@ -1,6 +1,9 @@
 Basic
 =====
-Start with a demo of basic logging using a ConsoleAppender and RollingFileAppender.
+
+Start with a demo of basic logging using a ConsoleAppender and
+RollingFileAppender.
+
 Contents: src/main/resources/logback-basic.xml
 
 Cyclic
@@ -22,15 +25,22 @@
 Importance of parameterized form
 ================================
 
-Log off (as sebastien). Turn all logging off. Results should should 
-that it takes about 1 microsecs to perform the "str"+i+".." computation, 
-whereas the "str {} ...", i form is about 30 times faster.
+Log off (as sebastien). Turn all logging off. Results should should
+that it takes about 1 microsecs to perform the "str"+i+".."
+computation, whereas the "str {} ...", i form is about 30 times
+faster.
 
 Marker example
 ==============
 Disable logging for all TRACE.
 Contents: src/main/resources/trace.xml
 
+SiftingAppender example
+=======================
+
+separate logging based on user.
+Contents: src/main/resources/sifting.xml
+
 Access logs
 ============
 on the console

Modified: logback-demo/trunk/src/etc/logback-access.xml
==============================================================================
--- logback-demo/trunk/src/etc/logback-access.xml	(original)
+++ logback-demo/trunk/src/etc/logback-access.xml	Thu Jun 11 14:22:36 2009
@@ -50,7 +50,7 @@
 	-->
 	 
 	
-	<!-- Part JMX 
+	<!-- Part JMX -->
   <filter class="ch.qos.logback.access.filter.CountingFilter">
 		<name>countingFilter</name>
 	</filter>	

Modified: logback-demo/trunk/src/main/java/ch/qos/logback/demo/Constants.java
==============================================================================
--- logback-demo/trunk/src/main/java/ch/qos/logback/demo/Constants.java	(original)
+++ logback-demo/trunk/src/main/java/ch/qos/logback/demo/Constants.java	Thu Jun 11 14:22:36 2009
@@ -3,7 +3,7 @@
 public class Constants {
   
   public static final String MGMNT_DOMAIN = "qos";
-  public static final String USER = "username";
+  public static final String USERID = "userid";
   
   public static final String GUESSED_NUMBER = "guessed_number";
   public static final Integer WINNING_NUMBER = new Integer(99);

Modified: logback-demo/trunk/src/main/java/ch/qos/logback/demo/ViewLastLog.java
==============================================================================
--- logback-demo/trunk/src/main/java/ch/qos/logback/demo/ViewLastLog.java	(original)
+++ logback-demo/trunk/src/main/java/ch/qos/logback/demo/ViewLastLog.java	Thu Jun 11 14:22:36 2009
@@ -29,7 +29,7 @@
 
   CyclicBufferAppender cyclicBufferAppender;
   HTMLLayout layout;
-  static String PATTERN = "%d%thread%level%logger{25}%mdc{" + Constants.USER
+  static String PATTERN = "%d%thread%level%logger{25}%mdc{" + Constants.USERID
       + "}%msg";
 
   @Override

Modified: logback-demo/trunk/src/main/java/ch/qos/logback/demo/login/LoginAction.java
==============================================================================
--- logback-demo/trunk/src/main/java/ch/qos/logback/demo/login/LoginAction.java	(original)
+++ logback-demo/trunk/src/main/java/ch/qos/logback/demo/login/LoginAction.java	Thu Jun 11 14:22:36 2009
@@ -26,9 +26,9 @@
 
       String username = form.getUsername();
       if (username != null) {
-        MDC.put(Constants.USER, username);
+        MDC.put(Constants.USERID, username);
         logger.info("Login: " + username + " just logged in.");
-        request.getSession().setAttribute(Constants.USER, username);
+        request.getSession().setAttribute(Constants.USERID, username);
         request.setAttribute("a", username);
       }
     }

Modified: logback-demo/trunk/src/main/java/ch/qos/logback/demo/login/LogoutAction.java
==============================================================================
--- logback-demo/trunk/src/main/java/ch/qos/logback/demo/login/LogoutAction.java	(original)
+++ logback-demo/trunk/src/main/java/ch/qos/logback/demo/login/LogoutAction.java	Thu Jun 11 14:22:36 2009
@@ -21,13 +21,13 @@
       ActionForm actionForm, HttpServletRequest request,
       HttpServletResponse response) throws Exception {
 
-    String username = (String)request.getSession().getAttribute(Constants.USER);
+    String username = (String)request.getSession().getAttribute(Constants.USERID);
     
-    MDC.remove(Constants.USER);
+    MDC.remove(Constants.USERID);
     logger.info("User: " + username + " just logged out.");
     
-    request.setAttribute(Constants.USER, username);
-    request.getSession().removeAttribute(Constants.USER);
+    request.setAttribute(Constants.USERID, username);
+    request.getSession().removeAttribute(Constants.USERID);
     
     return actionMapping.findForward("next");
   }

Modified: logback-demo/trunk/src/main/resources/logback.xml
==============================================================================
--- logback-demo/trunk/src/main/resources/logback.xml	(original)
+++ logback-demo/trunk/src/main/resources/logback.xml	Thu Jun 11 14:22:36 2009
@@ -1,83 +1,102 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 
 <configuration>
-	
-  <appender name="STDOUT"
-		class="ch.qos.logback.core.ConsoleAppender">
-		<layout class="ch.qos.logback.classic.PatternLayout">
-			<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{32} - %msg%n</pattern>
-		</layout>
-	</appender>
-  
-	<appender name="FILE"
-		class="ch.qos.logback.core.rolling.RollingFileAppender">
-		<File>logFile.log</File>
-		<rollingPolicy
-			class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-			<FileNamePattern>logFile.%d{yyyy-MM-dd_HH-mm}.log.zip</FileNamePattern>
+
+  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+    <layout>
+      <pattern>
+        %d{HH:mm:ss.SSS} [%thread] %-5level %logger{32} - %msg%n
+      </pattern>
+    </layout>
+  </appender>
+
+  <appender name="FILE"
+    class="ch.qos.logback.core.rolling.RollingFileAppender">
+    <File>logFile.log</File>
+    <rollingPolicy
+      class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+      <FileNamePattern>
+        logFile.%d{yyyy-MM-dd_HH-mm}.log.zip
+      </FileNamePattern>
       <maxHistory>5</maxHistory>
-		</rollingPolicy>
+    </rollingPolicy>
+
+    <layout>
+      <Pattern>
+        %-26(%d{HH:mm:ss,SSS} [%thread]) %-5level %logger{32} - %msg%n
+      </Pattern>
+    </layout>
+  </appender>
 
-		<layout class="ch.qos.logback.classic.PatternLayout">
-			<Pattern>%-26(%d{HH:mm:ss,SSS} [%thread]) %-5level %logger{32} - %msg%n
-			</Pattern>
-		</layout>
-	</appender>
-
-	<!-- Basic Cyclic buffer     
-	<appender name="CYCLIC"
-		class="ch.qos.logback.core.read.CyclicBufferAppender">
-		<MaxSize>512</MaxSize>
-	</appender>
+  <!-- Basic Cyclic buffer    
+    <appender name="CYCLIC"
+    class="ch.qos.logback.core.read.CyclicBufferAppender">
+    <MaxSize>512</MaxSize>
+    </appender>
   -->
 
-	<!-- Cyclic buffer with Evaluator   -->
-	<appender name="CYCLIC"
-		class="ch.qos.logback.core.read.CyclicBufferAppender">
-		<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
-			<evaluator name="loggingTaskEval">
-				<expression>
-					logger.getName().contains("LoggingTask") &amp;&amp;
-					message.contains("Howdydy-diddly-ho") &amp;&amp;
-					(timeStamp - event.getStartTime()) >= 20000
-				</expression>
-			</evaluator>
-			<OnMatch>DENY</OnMatch>
-		</filter>
-		<MaxSize>512</MaxSize>
+  <!-- Cyclic buffer with Evaluator -->
+  <appender name="CYCLIC"
+    class="ch.qos.logback.core.read.CyclicBufferAppender">
+    <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
+      <evaluator name="loggingTaskEval">
+        <expression>
+          logger.getName().contains("LoggingTask") &amp;&amp;
+          message.contains("Howdydy-diddly-ho") &amp;&amp; (timeStamp -
+          event.getStartTime()) >= 20000
+        </expression>
+      </evaluator>
+      <OnMatch>DENY</OnMatch>
+    </filter>
+    <MaxSize>512</MaxSize>
+  </appender>
+
+  <appender name="SIFT"
+    class="ch.qos.logback.classic.sift.SiftingAppender">
+    <discriminator>
+      <Key>userid</Key>
+      <DefaultValue>unknown</DefaultValue>
+    </discriminator>
+    <sift>
+      <appender name="FILE-${userid}"
+        class="ch.qos.logback.core.FileAppender">
+        <File>${userid}.log</File>
+        <Append>false</Append>
+        <layout>
+          <Pattern>
+            %d [%thread] %55(%5level %10mdc %logger{35}) - %msg%n
+          </Pattern>
+        </layout>
+      </appender>
+    </sift>
   </appender>
 
-	<!-- TurboFilter: by MDC value    -->
-  <turboFilter class="ch.qos.logback.classic.turbo.MDCFilter">
-		<MDCKey>username</MDCKey>
-		<Value>ceki</Value>
-		<OnMatch>ACCEPT</OnMatch>
-	</turboFilter>  
-  
-	
-	<!-- TurboFilter: by Marker   -->
-  <!--   
-  <turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter">
-    <Name>HOWDY_FILTER</Name>
-		<Marker>HOWDY</Marker>
-		<OnMatch>DENY</OnMatch>
-	</turboFilter>
-  -->
-	 
-  
-	<!-- JMX Configurator -->
-  <jmxConfigurator />
 
 
-	<root level="${lb_level:-ERROR}" >    
-		<appender-ref ref="STDOUT" />		
-    <appender-ref ref="FILE" />
+  <!-- TurboFilter: by MDC value 
+    <turboFilter class="ch.qos.logback.classic.turbo.MDCFilter">
+    <MDCKey>username</MDCKey>
+    <Value>sebastien</Value>
+    <OnMatch>ACCEPT</OnMatch>
+    </turboFilter>
+  -->
 
-    <!--		    
-		Part I: Basic Cyclic buffer        -->
-   	<appender-ref ref="CYCLIC" />
+  <!-- TurboFilter: by Marker   
+    <turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter">
+    <Name>HOWDY_FILTER</Name>
+    <Marker>HOWDY</Marker>
+    <OnMatch>DENY</OnMatch>
+    </turboFilter>
+  -->
+
+  <!-- JMX Configurator -->
+  <jmxConfigurator />
 
 
-	</root>
+  <root level="${lb_level:-ERROR}">
+    <appender-ref ref="STDOUT" />
+    <appender-ref ref="SIFT" />
+    <appender-ref ref="CYCLIC" />
+  </root>
 
 </configuration>

Added: logback-demo/trunk/src/main/resources/parts/sifting.xml
==============================================================================
--- (empty file)
+++ logback-demo/trunk/src/main/resources/parts/sifting.xml	Thu Jun 11 14:22:36 2009
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+ <appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender">
+    <discriminator>
+      <Key>userid</Key>
+      <DefaultValue>unknown</DefaultValue>
+    </discriminator>
+    <sift>
+      <appender name="FILE-${userid}" class="ch.qos.logback.core.FileAppender">
+        <File>${userid}.log</File>
+        <Append>false</Append>
+        <layout>
+          <Pattern>%d [%thread] %level %mdc %logger{35} - %msg%n</Pattern>
+        </layout>
+      </appender>
+    </sift>
+  </appender>
+

Modified: logback-demo/trunk/src/main/webapp/viewStatii.jsp
==============================================================================
--- logback-demo/trunk/src/main/webapp/viewStatii.jsp	(original)
+++ logback-demo/trunk/src/main/webapp/viewStatii.jsp	Thu Jun 11 14:22:36 2009
@@ -43,7 +43,7 @@
 
 <logic:notEmpty name="<%=Constants.STATUS %>">
 <pre>
-<bean:write name="<%=Constants.STATUS %>"/>
+<bean:write filter="false" name="<%=Constants.STATUS %>"/>
 </pre>
 </logic:notEmpty>
 


More information about the logback-dev mailing list