[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 -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=20c3ef5ec9336719396f67866630e3a5807afa34
http://github.com/ceki/logback/commit/20c3ef5ec9336719396f67866630e3a5807afa34
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 {
<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
<appender name="SMTP" class="ch.qos.logback.classic.net.SMTPAppender">
- <SMTPHost>NAME_OF_SMTP_HOST</SMTPHost>
+ <smtpHost>NAME_OF_SMTP_HOST</smtpHost>
<to>...</to>
<from>...</from>
- <subject>Prime - %mdc{number}</subject>
+ <subject>Prime - %mdc{number} by %mdc{userid} </subject>
<layout class="ch.qos.logback.classic.html.HTMLLayout">
<pattern>%date%level%logger{24}%msg</pattern>
</layout>
@@ -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>
+ <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();
+ }
+ }
+}</pre>
+
+
+ <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"><configuration scan="true" scanPeriod="3 seconds">
@@ -174,33 +215,73 @@ public class PrimeAction extends Action {
<appender name="SMTP" class="ch.qos.logback.classic.net.SMTPAppender">
<smtpHost>NAME_OF_SMTP_HOST</smtpHost>
+ <to>...</to>
+ <from>...</from>
+
+ <smtpHost>NAME_OF_SMTP_HOST</smtpHost>
<to>name at some.smtp.host</to>
<from>testing at ...</from>
- <subject>Prime - %mdc{number}</subject>
+ <subject>Prime - %mdc{number} by %mdc{userid} </subject>
<layout class="ch.qos.logback.classic.html.HTMLLayout">
<pattern>%date%level%logger{24}%msg</pattern>
</layout>
- <discriminator class="ch.qos.logback.classic.sift.MDCBasedDiscriminator">
- <key>uuid</key>
- <defaultValue>default</defaultValue>
- </discriminator>
-
<evaluator class="ch.qos.logback.classic.boolex.JaninoEventEvaluator">
<expression>
marker != null && marker.contains("SMTP_TRIGGER")
</expression>
</evaluator>
- <discriminator class="ch.qos.logback.classic.sift.MDCBasedDiscriminator">
- <key>uuid</key>
- <defaultValue>default</defaultValue>
- </discriminator>
+ <b><discriminator class="ch.qos.logback.classic.sift.MDCBasedDiscriminator"></b>
+ <b><key>txId</key></b>
+ <b><defaultValue>default</defaultValue></b>
+ <b></discriminator></b>
</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 & Transaction isolation</h3>
+ <h3>Selective triggering & 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"><configuration scan="true" scanPeriod="3 seconds">
@@ -208,7 +289,7 @@ public class PrimeAction extends Action {
<appender name="SMTP" class="ch.qos.logback.classic.net.SMTPAppender">
<SMTPHost>NAME_OF_SMTP_HOST</SMTPHost>
- <to>com</to>
+ <b><to>%mdc{txEmail}</to></b>
<from></from>
<subject>Prime - %mdc{number}</subject>
@@ -223,9 +304,9 @@ public class PrimeAction extends Action {
<evaluator class="ch.qos.logback.classic.boolex.JaninoEventEvaluator">
<expression>
- (mdc != null && mdc.get("txUser") != null &&
- ((String) mdc.get("txUser")).contains("Mickey") )
- &&
+ <b>(mdc != null &amp;&amp; mdc.get("txEmail") != null &amp;&amp; </b>
+ <b>((String) mdc.get("txEmail")).contains("+log") )</b>
+ &amp;&amp;
(marker != null && marker.contains("SMTP_TRIGGER") )
</expression>
</evaluator>
-----------------------------------------------------------------------
Summary of changes:
.../site/pages/recipes/emailPerTransaction.html | 117 +++++++++++++++++---
1 files changed, 99 insertions(+), 18 deletions(-)
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
More information about the logback-dev
mailing list