[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.25-51-g20c3ef5

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Tue Dec 21 23:01:17 CET 2010

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".

The branch, master has been updated
       via  20c3ef5ec9336719396f67866630e3a5807afa34 (commit)
      from  072bbaef8e8d0508e1660cc5d49b3e8c7112e881 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------

commit 20c3ef5ec9336719396f67866630e3a5807afa34
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Tue Dec 21 22:58:57 2010 +0100

    more edits

diff --git a/logback-site/src/site/pages/recipes/emailPerTransaction.html b/logback-site/src/site/pages/recipes/emailPerTransaction.html
index a13a167..9573605 100644
--- a/logback-site/src/site/pages/recipes/emailPerTransaction.html
+++ b/logback-site/src/site/pages/recipes/emailPerTransaction.html
@@ -133,10 +133,10 @@ public class PrimeAction extends Action {
   &lt;statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
   &lt;appender name="SMTP" class="ch.qos.logback.classic.net.SMTPAppender">
-    &lt;SMTPHost>NAME_OF_SMTP_HOST&lt;/SMTPHost>
+    &lt;smtpHost>NAME_OF_SMTP_HOST&lt;/smtpHost>
-    &lt;subject>Prime - %mdc{number}&lt;/subject>
+    &lt;subject>Prime - %mdc{number} by %mdc{userid} &lt;/subject>
     &lt;layout class="ch.qos.logback.classic.html.HTMLLayout">
@@ -164,9 +164,50 @@ public class PrimeAction extends Action {
    transactions. With a little effort, we can actually seperate events
    belonging to different transactions so that the outgoing email
    triggeed at the end of the transaction contains logs from that
-   transaction and only that one.
+   transaction and only that transaction.
+  <p>To isolate a given transaction, there must first be a way to
+  distinguish it from other transactions. Typically this would be
+  accomplished by putting the unique identifier of the transaction
+  into the the MDC.
+  </p>
+  <pre class="prettyprint source">String transactionId = ...; // extract id from transaction 
+MDC.put("txId", transactionId); </pre>
+  <p>In the <a
+  href="http://logback-demo.qos.ch/xref/ch/qos/logback/demo/UserServletFilter.html"><code>UserServletFilter</code></a>
+  class, this is done by retreiving the id of the session and putting
+  it into the MDC under the key "txId".</p>
+    <pre class="prettyprint source">public class UserServletFilter implements Filter {
+   public void doFilter(ServletRequest request, ServletResponse response,
+                       FilterChain chain) throws IOException, ServletException {
+    HttpServletRequest req = (HttpServletRequest) request;
+    HttpSession session = req.getSession();
+    MDC.put("txId", session.getId());
+    ...
+    try {
+      // invoke subsequent filters
+      chain.doFilter(request, response);
+    } finally {
+      // always clear the MDC at the end of the request
+      MDC.clear();
+    }
+  }
+  <p>By setting an appropriate discriminator in SMTPAppender, you can
+  can scatter incoming events into different buffers according to the
+  value returned by the discriminator. Given that each request session
+  is placed under the MDC key "txId", we can use an MDC-based
+  discriminator to isolate the logs generated by each transaction.
+  </p>
   <pre class="prettyprint source">&lt;configuration scan="true" scanPeriod="3 seconds">
@@ -174,33 +215,73 @@ public class PrimeAction extends Action {
   &lt;appender name="SMTP" class="ch.qos.logback.classic.net.SMTPAppender">
+    &lt;to>...&lt;/to>                                         
+    &lt;from>...&lt;/from>
+    &lt;smtpHost>NAME_OF_SMTP_HOST&lt;/smtpHost>
     &lt;to>name at some.smtp.host&lt;/to>
     &lt;from>testing at ...&lt;/from>
-    &lt;subject>Prime - %mdc{number}&lt;/subject>
+    &lt;subject>Prime - %mdc{number} by %mdc{userid} &lt;/subject>
     &lt;layout class="ch.qos.logback.classic.html.HTMLLayout">
-    &lt;discriminator class="ch.qos.logback.classic.sift.MDCBasedDiscriminator">
-      &lt;key>uuid&lt;/key>
-      &lt;defaultValue>default&lt;/defaultValue>
-    &lt;/discriminator>
     &lt;evaluator class="ch.qos.logback.classic.boolex.JaninoEventEvaluator">
         marker != null &amp;&amp; marker.contains("SMTP_TRIGGER") 
-    &lt;discriminator class="ch.qos.logback.classic.sift.MDCBasedDiscriminator">
-      &lt;key>uuid&lt;/key>
-      &lt;defaultValue>default&lt;/defaultValue>
-    &lt;/discriminator>
+    <b>&lt;discriminator class="ch.qos.logback.classic.sift.MDCBasedDiscriminator"></b>
+      <b>&lt;key>txId&lt;/key></b>
+      <b>&lt;defaultValue>default&lt;/defaultValue></b>
+    <b>&lt;/discriminator></b>
   &lt;/appender>  </pre>
+   <p>After starting the logback-demo web-application with the above
+   configuration file (with <span class="option">smtpHost</span> and
+   <span class="option">to</span> options adapted for my environment)
+   on localhost and then visiting the <a
+   href="http://localhost:8070/logback-demo/prime.jsp">Prime
+   number</a> page to factoize the number 123, I received the
+   following email:
+   </p>
+   <img src="images/factorEmail0.png" alt="selective email0"/>
+   <p>Note that the above email contains the logs generated by the
+   factorization of the number 123, without log pollution from any
+   other "transaction".
+   </p>
-  <h3>Selective triggering &amp; Transaction isolation</h3>
+  <h3>Selective triggering &amp; recipient addressing with transaction isolation</h3>
+  <p>In a real world scenario, receiving isolated transactions is not
+  enough. You would need to trigger outgoing emails only for certain
+  users, typically QA engineers such as Dave and Carol. Moreover, you
+  would want the emails generated by transaction made by Carol to
+  Carol's mailbox and those generated by Dave to Dave's mailbox.</p>
+  <p>Selective triggering and addressing are two distinct
+  problems. Depending on the exact circumstances, there are many ways
+  of tackling these two issues. However, for the sake of simplicity,
+  let us assume that the SMTP server at Fooware.com accepts <a
+  href="http://en.wikipedia.org/wiki/Email_address#Address_tags">address
+  tags</a>. Such an SMTP server treats an incoming message sent to
+  username+xyz at fooware.com as if it were addressed to
+  username at fooware.com, effectively stripping the +xyz part.</p>
+  <p>Let us further assume that we can somehow extract the email
+  address of the user from the contents of her transaction, via a
+  database lookup or perhaps some other means. The extracted email
+  addressed is placed into the MDC under the key "txEmail".
+  </p>
+  <p>Upon a logging event marked as SMTP_TRIGGER, the following
+  confugration file will trigger an email message addressed to the
+  value of "%mdc{txEmail}" but only if it contains the string "+log".
+  </p>
   <pre class="prettyprint source">&lt;configuration scan="true" scanPeriod="3 seconds">
@@ -208,7 +289,7 @@ public class PrimeAction extends Action {
   &lt;appender name="SMTP" class="ch.qos.logback.classic.net.SMTPAppender">
-    &lt;to>com&lt;/to>
+    <b>&lt;to>%mdc{txEmail}&lt;/to></b>
     &lt;subject>Prime - %mdc{number}&lt;/subject>
@@ -223,9 +304,9 @@ public class PrimeAction extends Action {
     &lt;evaluator class="ch.qos.logback.classic.boolex.JaninoEventEvaluator">
-        (mdc != null &amp;&amp; mdc.get("txUser") != null &amp;&amp; 
-             ((String) mdc.get("txUser")).contains("Mickey") )
-        &amp;&amp;
+        <b>(mdc != null &amp;amp;&amp;amp; mdc.get("txEmail") != null &amp;amp;&amp;amp; </b>
+            <b>((String) mdc.get("txEmail")).contains("+log") )</b>
+        &amp;amp;&amp;amp;
         (marker != null  &amp;&amp; marker.contains("SMTP_TRIGGER") )


Summary of changes:
 .../site/pages/recipes/emailPerTransaction.html    |  117 +++++++++++++++++---
 1 files changed, 99 insertions(+), 18 deletions(-)

Logback: the generic, reliable, fast and flexible logging framework.

More information about the logback-dev mailing list