[logback-dev] svn commit: r628 - in logback/trunk/logback-access/src/main/java/ch/qos/logback/access: . html net

noreply.seb at qos.ch noreply.seb at qos.ch
Fri Oct 6 16:05:02 CEST 2006


Author: seb
Date: Fri Oct  6 16:05:02 2006
New Revision: 628

Added:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/html/
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/html/HTMLLayout.java
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/html/package.html
Modified:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/PatternLayout.java
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/SMTPAppender.java

Log:
- added HTMLLayout for access module
- minor fix on SMTPAppender javadoc

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/PatternLayout.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/PatternLayout.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/PatternLayout.java	Fri Oct  6 16:05:02 2006
@@ -212,7 +212,7 @@
  */
 public class PatternLayout extends PatternLayoutBase implements AccessLayout {
 
-  static final Map<String, String> defaultConverterMap = new HashMap<String, String>();
+  public static final Map<String, String> defaultConverterMap = new HashMap<String, String>();
 
   public static String CLF_PATTERN = "%h %l %u %t \"%r\" %s %b";
 

Added: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/html/HTMLLayout.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/html/HTMLLayout.java	Fri Oct  6 16:05:02 2006
@@ -0,0 +1,129 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * 
+ * Copyright (C) 1999-2006, 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
+ * Software Foundation.
+ */
+
+package ch.qos.logback.access.html;
+
+import java.util.Map;
+
+import ch.qos.logback.access.AccessLayout;
+import ch.qos.logback.access.PatternLayout;
+import ch.qos.logback.access.spi.AccessEvent;
+import ch.qos.logback.core.html.HTMLLayoutBase;
+import ch.qos.logback.core.html.NOPThrowableRenderer;
+import ch.qos.logback.core.pattern.Converter;
+
+/**
+ * 
+ * HTMLLayout outputs events in an HTML table. 
+ * <p>
+ * The content of the table columns are specified using a conversion pattern. 
+ * See {@link ch.qos.logback.access.PatternLayout} for documentation on the
+ * available patterns.
+ * <p>
+ * A user-specified external CSS file can be linked to the html page. 
+ * In case one does not want to customize the html output, an internal CSS style
+ * is used.
+ * 
+ * The HTMLLayout is often used in conjunction with SMTPAppender, to
+ * send a nicely formatted html email. Of course, it can be used with any
+ * other Appender.
+ * 
+ * In case on wants to use the HTMLLayout with a SMTPAppender, here is a sample
+ * configuration file that can be used.
+ * 
+ * <pre>
+ * &lt;configuration&gt;
+ *   &lt;appender name="SMTP" class="ch.qos.logback.access.net.SMTPAppender"&gt;
+ *     &lt;layout class="ch.qos.logback.access.html.HTMLLayout"&gt;
+ *       &lt;param name="pattern" value="%remoteIP%date%requestURL%statusCode%bytesSent" /&gt;
+ *     &lt;/layout&gt;
+ *    &lt;param name="From" value="sender.email at domain.net" /&gt;
+ *    &lt;param name="SMTPHost" value="mail.domain.net" /&gt;
+ *    &lt;param name="Subject" value="LastEvent: %statusCode %requestURL" /&gt;
+ *    &lt;param name="To" value="destination.email at domain.net" /&gt;
+ *   &lt;/appender&gt;
+ *
+ *   &lt;appender-ref ref="SMTP" /&gt;
+ * &lt;/configuration&gt;
+ *</pre>
+ * <p>
+ * In this configuration file, the <em>throwableRenderer</em> element specifies the default
+ * implementation of IThrowableRenderer. It could be omitted, but is showed for educationnal
+ * purposes.
+ * <p>
+ * @author Ceki G&uuml;lc&uuml;
+ * @author S&eacute;bastien Pennec
+ */
+public class HTMLLayout extends HTMLLayoutBase implements AccessLayout {
+
+  /**
+   * Default pattern string for log output. Currently set to the string <b>"%m"
+   * </b> which just prints the application supplied message.
+   */
+  static final String DEFAULT_CONVERSION_PATTERN = "%date%thread%level%logger%mdc%msg";
+
+  /**
+   * Constructs a PatternLayout using the DEFAULT_LAYOUT_PATTERN.
+   * 
+   * The default pattern just produces the application supplied message.
+   */
+  public HTMLLayout() {
+    pattern = DEFAULT_CONVERSION_PATTERN;
+    throwableRenderer = new NOPThrowableRenderer();
+  }
+  
+  @Override
+  protected Map<String, String> getDefaultConverterMap() {
+    return PatternLayout.defaultConverterMap;
+  }
+
+  public String doLayout(Object event) {
+    return doLayout((AccessEvent) event);
+  }
+
+  public String doLayout(AccessEvent event) {
+    StringBuffer buf = new StringBuffer();
+    handleTableClosing(buf);
+
+    boolean odd = true;
+    if (((counter++) & 1) == 0) {
+      odd = false;
+    }
+
+    buf.append(LINE_SEP);
+    buf.append("<tr class=\"");
+    if (odd) {
+      buf.append(" odd\">");
+    } else {
+      buf.append(" even\">");
+    }
+    buf.append(LINE_SEP);
+
+    Converter c = head;
+    while (c != null) {
+      appendEventToBuffer(buf, c, event);
+      c = c.getNext();
+    }
+    buf.append("</tr>");
+    buf.append(LINE_SEP);
+
+    return buf.toString();
+  }
+
+  private void appendEventToBuffer(StringBuffer buf, Converter c,
+      AccessEvent event) {
+    buf.append("<td class=\"");
+    buf.append(computeConverterName(c));
+    buf.append("\">");
+    buf.append(c.convert(event));
+    buf.append("</td>");
+    buf.append(LINE_SEP);
+  }
+}

Added: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/html/package.html
==============================================================================
--- (empty file)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/html/package.html	Fri Oct  6 16:05:02 2006
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+
+<html> 
+  <head>
+    <title></title>
+  </head>
+  
+  <body>
+    
+    <p>Contains classes to format log output in HTML.</p>
+
+  </body> 
+</html>
\ No newline at end of file

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/SMTPAppender.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/SMTPAppender.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/SMTPAppender.java	Fri Oct  6 16:05:02 2006
@@ -30,7 +30,7 @@
  * application context.
  * <p> 
  * By default, the email is sent everything an event has a status code of 
- * 500 (server error) or higher.
+ * <em>500 (server error) or higher</em>.
  * <p>
  * @author Ceki G&uuml;lc&uuml;
  * @author S&eacute;bastien Pennec



More information about the logback-dev mailing list