[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.25-41-gfc45086
added by portage for gitosis-gentoo
git-noreply at pixie.qos.ch
Mon Dec 13 17:17:23 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 fc4508616906b773dd9d93d4e0d2c45628d3f7b5 (commit)
from 1c9ce863a577cf5075088eb66ca5353f4de0e209 (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=fc4508616906b773dd9d93d4e0d2c45628d3f7b5
http://github.com/ceki/logback/commit/fc4508616906b773dd9d93d4e0d2c45628d3f7b5
commit fc4508616906b773dd9d93d4e0d2c45628d3f7b5
Author: Ceki Gulcu <ceki at qos.ch>
Date: Mon Dec 13 17:17:28 2010 +0100
add support for dynamic destination address computation in SMTPAppender
diff --git a/logback-access/src/main/java/ch/qos/logback/access/PatternLayout.java b/logback-access/src/main/java/ch/qos/logback/access/PatternLayout.java
index 40917f3..43590ed 100644
--- a/logback-access/src/main/java/ch/qos/logback/access/PatternLayout.java
+++ b/logback-access/src/main/java/ch/qos/logback/access/PatternLayout.java
@@ -182,5 +182,4 @@ public class PatternLayout extends PatternLayoutBase<AccessEvent> {
}
super.start();
}
-
}
diff --git a/logback-access/src/main/java/ch/qos/logback/access/net/SMTPAppender.java b/logback-access/src/main/java/ch/qos/logback/access/net/SMTPAppender.java
index 4d48cc8..4584e4f 100644
--- a/logback-access/src/main/java/ch/qos/logback/access/net/SMTPAppender.java
+++ b/logback-access/src/main/java/ch/qos/logback/access/net/SMTPAppender.java
@@ -79,4 +79,12 @@ public class SMTPAppender extends SMTPAppenderBase<AccessEvent> {
pl.start();
return pl;
}
+
+ protected PatternLayout makeNewToPatternLayout(String toPattern) {
+ PatternLayout pl = new PatternLayout();
+ pl.setPattern(toPattern);
+ return pl;
+ }
+
+
}
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java b/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java
index a3fc208..3a6442d 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java
@@ -139,5 +139,4 @@ public class PatternLayout extends PatternLayoutBase<ILoggingEvent> {
}
return writeLoopOnConverters(event);
}
-
}
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/net/SMTPAppender.java b/logback-classic/src/main/java/ch/qos/logback/classic/net/SMTPAppender.java
index c30e24c..262bd91 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/net/SMTPAppender.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/net/SMTPAppender.java
@@ -101,4 +101,10 @@ public class SMTPAppender extends SMTPAppenderBase<ILoggingEvent> {
pl.start();
return pl;
}
+
+ protected PatternLayout makeNewToPatternLayout(String toPattern) {
+ PatternLayout pl = new PatternLayout();
+ pl.setPattern(toPattern+"%nopex");
+ return pl;
+ }
}
diff --git a/logback-classic/src/test/groovy/ch/qos/logback/classic/gaffer/ConfigurationDelegateTest.groovy b/logback-classic/src/test/groovy/ch/qos/logback/classic/gaffer/ConfigurationDelegateTest.groovy
index ea94697..2e5d65f 100644
--- a/logback-classic/src/test/groovy/ch/qos/logback/classic/gaffer/ConfigurationDelegateTest.groovy
+++ b/logback-classic/src/test/groovy/ch/qos/logback/classic/gaffer/ConfigurationDelegateTest.groovy
@@ -189,7 +189,7 @@ class ConfigurationDelegateTest {
PatternLayout layout = sa.layout
assertEquals("%m%n", layout.pattern)
- assertEquals(["a", "b"], sa.toList.sort());
+ assertEquals(["a%nopex", "b%nopex"], sa.getToAsListOfString().sort());
}
// test parent injection
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/net/DilutedSMTPAppenderTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/net/DilutedSMTPAppenderTest.java
index 5e3f912..53bbc0c 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/net/DilutedSMTPAppenderTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/net/DilutedSMTPAppenderTest.java
@@ -81,9 +81,7 @@ public class DilutedSMTPAppenderTest {
addressArray = null;
address = null;
- addressArray = appender.getMessage().getAllRecipients();
- address = addressArray[0];
- assertEquals("sebastien.nospam at qos.ch", address.toString());
+ assertEquals("sebastien.nospam at qos.ch%nopex", appender.getToAsListOfString().get(0));
assertEquals("logging report", appender.getSubject());
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/net/PackageTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/net/PackageTest.java
index 076d7ca..f97ea53 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/net/PackageTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/net/PackageTest.java
@@ -19,6 +19,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses( { SyslogAppenderTest.class, DilutedSMTPAppenderTest.class,
- SocketAppenderTest.class, JMSQueueAppenderTest.class, JMSTopicAppenderTest.class })
+ SocketAppenderTest.class, JMSQueueAppenderTest.class, JMSTopicAppenderTest.class,
+ SMTPAppender_GreenTest.class, SMTPAppender_SubethaSMTPTest.class })
public class PackageTest {
}
\ No newline at end of file
diff --git a/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java b/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java
index 6d1ee31..01f9dbe 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java
@@ -35,6 +35,7 @@ import ch.qos.logback.core.Layout;
import ch.qos.logback.core.boolex.EvaluationException;
import ch.qos.logback.core.boolex.EventEvaluator;
import ch.qos.logback.core.helpers.CyclicBuffer;
+import ch.qos.logback.core.pattern.PatternLayoutBase;
import ch.qos.logback.core.sift.DefaultDiscriminator;
import ch.qos.logback.core.sift.Discriminator;
import ch.qos.logback.core.spi.CyclicBufferTracker;
@@ -58,18 +59,21 @@ import ch.qos.logback.core.util.OptionHelper;
*/
public abstract class SMTPAppenderBase<E> extends AppenderBase<E> {
-
+ static InternetAddress[] EMPTY_IA_ARRAY = new InternetAddress[0];
// ~ 14 days
static final int MAX_DELAY_BETWEEN_STATUS_MESSAGES = 1228800 * CoreConstants.MILLIS_IN_ONE_SECOND;
long lastTrackerStatusPrint = 0;
int delayBetweenStatusMessages = 300 * CoreConstants.MILLIS_IN_ONE_SECOND;
+
+
+
protected Layout<E> subjectLayout;
protected Layout<E> layout;
- private List<String> toList = new ArrayList<String>();
+ private List<PatternLayoutBase<E>> toPatternLayoutList = new ArrayList<PatternLayoutBase<E>>();
private String from;
private String subjectStr = null;
private String smtpHost;
@@ -150,8 +154,6 @@ public abstract class SMTPAppenderBase<E> extends AppenderBase<E> {
mimeMsg.setFrom();
}
- mimeMsg.setRecipients(Message.RecipientType.TO, parseAddress(toList));
-
subjectLayout = makeSubjectLayout(subjectStr);
started = true;
@@ -190,7 +192,7 @@ public abstract class SMTPAppenderBase<E> extends AppenderBase<E> {
if (lastTrackerStatusPrint + delayBetweenStatusMessages < now) {
addInfo("SMTPAppender [" + name + "] is tracking [" + cbTracker.size() + "] buffers");
lastTrackerStatusPrint = now;
- // quadruple 'delay' assuming less than max delay
+ // quadruple 'delay' assuming less than max delay
if (delayBetweenStatusMessages < MAX_DELAY_BETWEEN_STATUS_MESSAGES) {
delayBetweenStatusMessages *= 4;
}
@@ -246,29 +248,35 @@ public abstract class SMTPAppenderBase<E> extends AppenderBase<E> {
}
}
- InternetAddress[] parseAddress(List<String> addressList) {
+ private List<InternetAddress> parseAddress(E event) {
+ int len = toPatternLayoutList.size();
- InternetAddress[] iaArray = new InternetAddress[addressList.size()];
+ List<InternetAddress> iaList = new ArrayList<InternetAddress>();
- for (int i = 0; i < addressList.size(); i++) {
+ for (int i = 0; i < len; i++) {
try {
- InternetAddress[] tmp = InternetAddress.parse(addressList.get(i), true);
+ PatternLayoutBase<E> emailPL = toPatternLayoutList.get(i);
+ String email = emailPL.doLayout(event);
+ if(email == null || email.length() == 0) {
+ continue;
+ }
+ InternetAddress[] tmp = InternetAddress.parse(email, true);
// one <To> element should contain one email address
- iaArray[i] = tmp[0];
+ iaList.add(tmp[0]);
} catch (AddressException e) {
- addError("Could not parse address [" + addressList.get(i) + "].", e);
- return null;
+ addError("Could not parse email address for [" + toPatternLayoutList.get(i) + "] for event ["+event+"]", e);
+ return iaList;
}
}
- return iaArray;
+ return iaList;
}
/**
* Returns value of the <b>toList</b> option.
*/
- public List<String> getToList() {
- return toList;
+ public List<PatternLayoutBase<E>> getToList() {
+ return toPatternLayoutList;
}
/**
@@ -306,6 +314,13 @@ public abstract class SMTPAppenderBase<E> extends AppenderBase<E> {
charsetEncoding);
}
+ List<InternetAddress> destinationAddresses = parseAddress(lastEventObject);
+ if(destinationAddresses.isEmpty()) {
+ addInfo("Empty destination address. Aborting email transmission");
+ return;
+ }
+ mimeMsg.setRecipients(Message.RecipientType.TO, destinationAddresses.toArray(EMPTY_IA_ARRAY));
+
String contentType = layout.getContentType();
if (ContentTypeUtil.isTextual(contentType)) {
@@ -326,6 +341,8 @@ public abstract class SMTPAppenderBase<E> extends AppenderBase<E> {
}
}
+
+
abstract protected void fillBuffer(CyclicBuffer<E> cb, StringBuffer sbuf);
/**
@@ -437,17 +454,28 @@ public abstract class SMTPAppenderBase<E> extends AppenderBase<E> {
this.discriminator = discriminator;
}
- /**
- * The <b>To</b> option takes a string value which should be an e-mail address
- * of one of the recipients.
- */
public void addTo(String to) {
- this.toList.add(to);
+ if(to == null || to.length() == 0) {
+ throw new IllegalArgumentException("Null or empty <to> property");
+ }
+ PatternLayoutBase plb = makeNewToPatternLayout(to.trim());
+ plb.setContext(context);
+ plb.start();
+ this.toPatternLayoutList.add(plb);
}
- // for testing purpose only
+ abstract protected PatternLayoutBase<E> makeNewToPatternLayout(String toPattern);
+
+ public List<String> getToAsListOfString() {
+ List<String> toList = new ArrayList<String>();
+ for(PatternLayoutBase plb: toPatternLayoutList) {
+ toList.add(plb.getPattern());
+ }
+ return toList;
+ }
- public Message getMessage() {
+ // for testing purpose only
+ public Message getMessage() {
return mimeMsg;
}
diff --git a/logback-site/src/site/pages/recipes/captureHttp.html b/logback-site/src/site/pages/recipes/captureHttp.html
index 244478a..86488e6 100644
--- a/logback-site/src/site/pages/recipes/captureHttp.html
+++ b/logback-site/src/site/pages/recipes/captureHttp.html
@@ -200,11 +200,11 @@ Set-Cookie: JSESSIONID=bgebt99ce9om;path=/logback-demo
probe made by the load-balancer.
</p>
- <p>We need to a way to filter-out these probes so that they are
- no longer contaminate the log output. However, we need a way to
+ <p>We need to a way to filter-out these probes so that they no
+ longer contaminate the log output. In other words, we need to
distinguish probes emanating from the load-balancer from other
- requests that we deem desirable. The contents of the requests
- can give you clues about possible criteria.</p>
+ requests. The contents of the probes can give us clues about
+ possible distinguishing criteria.</p>
<p>Here is a sample probe as logged by logback-access:</p>
@@ -218,16 +218,17 @@ X-Powered-By: Servlet 2.4;
Cache-Control: no-cache
Pragma: No-cache </pre>
- <p>From the above, we can see that the load-blancer probes use
- the <a
+ <p>From the above, we can see that the load-blancer probes
+ employ the <a
href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4">HTTP
HEAD method</a> instead of the usual GET or POST. We can also
see that the request URI for the probes contains the string
"probe".</p>
<p>Here is a <em>logback-access.xml</em> configuration file
- which will deny any access event which uses the HEAD
- method. Note that it is based on Janino.</p>
+ which will deny any <code>AccessEvent</code> where the method is
+ HEAD. Note that events are evaluated using
+ <code>JaninoEventEvaluator</code> which requires Janino.</p>
<pre class="prettyprint source"><configuration>
<!-- always a good idea to install OnConsoleStatusListener -->
-----------------------------------------------------------------------
Summary of changes:
.../java/ch/qos/logback/access/PatternLayout.java | 1 -
.../ch/qos/logback/access/net/SMTPAppender.java | 8 ++
.../java/ch/qos/logback/classic/PatternLayout.java | 1 -
.../ch/qos/logback/classic/net/SMTPAppender.java | 6 ++
.../gaffer/ConfigurationDelegateTest.groovy | 2 +-
.../classic/net/DilutedSMTPAppenderTest.java | 4 +-
.../ch/qos/logback/classic/net/PackageTest.java | 3 +-
.../ch/qos/logback/core/net/SMTPAppenderBase.java | 72 ++++++++++++++------
.../src/site/pages/recipes/captureHttp.html | 17 +++--
9 files changed, 77 insertions(+), 37 deletions(-)
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
More information about the logback-dev
mailing list