logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1400488 - in /logging/log4j/log4j2/trunk: core/src/main/java/org/apache/logging/log4j/core/layout/HTMLLayout.java core/src/test/java/org/apache/logging/log4j/core/layout/HTMLLayoutTest.java src/changes/changes.xml
Date Sat, 20 Oct 2012 17:08:19 GMT
Author: rgoers
Date: Sat Oct 20 17:08:19 2012
New Revision: 1400488

URL: http://svn.apache.org/viewvc?rev=1400488&view=rev
Log:
LOG4J2-29 - Added font and fontSize parameters to HTMLLayout.

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/HTMLLayout.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/HTMLLayoutTest.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/HTMLLayout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/HTMLLayout.java?rev=1400488&r1=1400487&r2=1400488&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/HTMLLayout.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/HTMLLayout.java
Sat Oct 20 17:08:19 2012
@@ -32,6 +32,7 @@ import java.io.StringWriter;
 import java.lang.management.ManagementFactory;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
+import java.util.List;
 
 /**
  * This layout outputs events in a HTML table.
@@ -61,11 +62,47 @@ public final class HTMLLayout extends Ab
 
     private final String contentType;
 
-    private HTMLLayout(boolean locationInfo, String title, String contentType, Charset charset)
{
+    private enum FontSize {
+        SMALLER("smaller"), XXSMALL("xx-small"), XSMALL("x-small"), SMALL("small"), MEDIUM("medium"),
LARGE("large"),
+        XLARGE("x-large"), XXLARGE("xx-large"),  LARGER("larger");
+
+        private final String size;
+
+        private FontSize(String size) {
+            this.size = size;
+        }
+
+        public String getFontSize() {
+            return size;
+        }
+
+        public static FontSize getFontSize(String size) {
+            for (FontSize fontSize : values()) {
+                if (fontSize.size.equals(size)) {
+                    return fontSize;
+                }
+            }
+            return SMALL;
+        }
+
+        public FontSize larger() {
+            return this.ordinal() < XXLARGE.ordinal() ? FontSize.values()[this.ordinal()
+ 1] : this;
+        }
+    }
+
+    private final String font;
+    private final String fontSize;
+    private final String headerSize;
+
+    private HTMLLayout(boolean locationInfo, String title, String contentType, Charset charset,
+                       String font, String fontSize, String headerSize) {
         super(charset);
         this.locationInfo = locationInfo;
         this.title = title;
         this.contentType = contentType;
+        this.font = font;
+        this.fontSize = fontSize;
+        this.headerSize = headerSize;
     }
 
     /**
@@ -125,14 +162,16 @@ public final class HTMLLayout extends Ab
         sbuf.append("</tr>").append(LINE_SEP);
 
         if (event.getContextStack().getDepth() > 0) {
-            sbuf.append("<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : xx-small;\"
colspan=\"6\" ");
+            sbuf.append("<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : ").append(fontSize);
+            sbuf.append(";\" colspan=\"6\" ");
             sbuf.append("title=\"Nested Diagnostic Context\">");
             sbuf.append("NDC: ").append(Transform.escapeTags(event.getContextStack().toString()));
             sbuf.append("</td></tr>").append(LINE_SEP);
         }
 
         if (event.getContextMap().size() > 0) {
-            sbuf.append("<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : xx-small;\"
colspan=\"6\" ");
+            sbuf.append("<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : ").append(fontSize);
+            sbuf.append(";\" colspan=\"6\" ");
             sbuf.append("title=\"Mapped Diagnostic Context\">");
             sbuf.append("MDC: ").append(Transform.escapeTags(event.getContextMap().toString()));
             sbuf.append("</td></tr>").append(LINE_SEP);
@@ -140,7 +179,8 @@ public final class HTMLLayout extends Ab
 
         Throwable throwable = event.getThrown();
         if (throwable != null) {
-            sbuf.append("<tr><td bgcolor=\"#993300\" style=\"color:White; font-size
: xx-small;\" colspan=\"6\">");
+            sbuf.append("<tr><td bgcolor=\"#993300\" style=\"color:White; font-size
: ").append(fontSize);
+            sbuf.append(";\" colspan=\"6\">");
             appendThrowableAsHTML(throwable, sbuf);
             sbuf.append("</td></tr>").append(LINE_SEP);
         }
@@ -198,7 +238,8 @@ public final class HTMLLayout extends Ab
         sbuf.append("<title>").append(title).append("</title>").append(LINE_SEP);
         sbuf.append("<style type=\"text/css\">").append(LINE_SEP);
         sbuf.append("<!--").append(LINE_SEP);
-        sbuf.append("body, table {font-family: arial,sans-serif; font-size: x-small;}").append(LINE_SEP);
+        sbuf.append("body, table {font-family:").append(font).append("; font-size: ");
+        sbuf.append(headerSize).append(";}").append(LINE_SEP);
         sbuf.append("th {background: #336699; color: #FFFFFF; text-align: left;}").append(LINE_SEP);
         sbuf.append("-->").append(LINE_SEP);
         sbuf.append("</style>").append(LINE_SEP);
@@ -248,7 +289,9 @@ public final class HTMLLayout extends Ab
     public static HTMLLayout createLayout(@PluginAttr("locationInfo") String locationInfo,
                                           @PluginAttr("title") String title,
                                           @PluginAttr("contentType") String contentType,
-                                          @PluginAttr("charset") String charset) {
+                                          @PluginAttr("charset") String charset,
+                                          @PluginAttr("fontSize") String fontSize,
+                                          @PluginAttr("fontName") String font) {
         Charset c = Charset.isSupported("UTF-8") ? Charset.forName("UTF-8") : Charset.defaultCharset();
         if (charset != null) {
             if (Charset.isSupported(charset)) {
@@ -257,6 +300,12 @@ public final class HTMLLayout extends Ab
                 LOGGER.error("Charset " + charset + " is not supported for layout, using
" + c.displayName());
             }
         }
+        if (font == null) {
+            font = "arial,sans-serif";
+        }
+        FontSize fs = FontSize.getFontSize(fontSize);
+        fontSize = fs.getFontSize();
+        String headerSize = fs.larger().getFontSize();
         boolean info = locationInfo == null ? false : Boolean.valueOf(locationInfo);
         if (title == null) {
             title = DEFAULT_TITLE;
@@ -264,6 +313,6 @@ public final class HTMLLayout extends Ab
         if (contentType == null) {
             contentType = DEFAULT_CONTENT_TYPE;
         }
-        return new HTMLLayout(info, title, contentType, c);
+        return new HTMLLayout(info, title, contentType, c, font, fontSize, headerSize);
     }
 }

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/HTMLLayoutTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/HTMLLayoutTest.java?rev=1400488&r1=1400487&r2=1400488&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/HTMLLayoutTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/HTMLLayoutTest.java
Sat Oct 20 17:08:19 2012
@@ -54,7 +54,7 @@ public class HTMLLayoutTest {
     }
 
     private static final String body =
-        "<tr><td bgcolor=\"#993300\" style=\"color:White; font-size : xx-small;\"
colspan=\"6\">java.lang.NullPointerException: test";
+        "<tr><td bgcolor=\"#993300\" style=\"color:White; font-size : small;\" colspan=\"6\">java.lang.NullPointerException:
test";
 
 
     /**
@@ -64,7 +64,7 @@ public class HTMLLayoutTest {
     public void testLayout() throws Exception {
 
         // set up appender
-        HTMLLayout layout = HTMLLayout.createLayout("true", null, null, null);
+        HTMLLayout layout = HTMLLayout.createLayout("true", null, null, null, "small", null);
         ListAppender appender = new ListAppender("List", null, layout, true, false);
         appender.start();
 
@@ -90,10 +90,10 @@ public class HTMLLayoutTest {
         appender.stop();
 
         List<String> list = appender.getMessages();
-
         assertTrue("Incorrect number of lines. Require at least 85 " + list.size(), list.size()
> 85);
         assertTrue("Incorrect header", list.get(3).equals("<title>Log4J Log Messages</title>"));
         assertTrue("Incorrect footer", list.get(list.size() - 1).equals("</body></html>"));
         assertTrue("Incorrect body", list.get(61).equals(body));
+
     }
 }

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1400488&r1=1400487&r2=1400488&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sat Oct 20 17:08:19 2012
@@ -23,6 +23,9 @@
 
   <body>
     <release version="2.0-beta3" date="TBD" description= "Bug fixes and enhancements">
+      <action issue="LOG4J2-29" dev="rgoers" type="update">
+        Added font and fontSize parameters to HTMLLayout.
+      </action>
       <action issue="LOG4J2-55" dev="rgoers" type="add">
         Added ability to configure from an InputSource.
       </action>



Mime
View raw message