You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by mi...@apache.org on 2016/08/17 09:53:42 UTC
[2/3] logging-log4j2 git commit: Support Log4j 1 HtmlLayout options
Support Log4j 1 HtmlLayout options
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/bbae0af6
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/bbae0af6
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/bbae0af6
Branch: refs/heads/master
Commit: bbae0af6eb499a0e3131d96a8168d69fdadcfed9
Parents: ff36b4a
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Wed Aug 17 10:57:37 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Wed Aug 17 10:57:37 2016 +0200
----------------------------------------------------------------------
.../log4j/config/Log4j1ConfigurationFactory.java | 8 +++++++-
.../log4j/config/Log4j1ConfigurationFactoryTest.java | 5 +++--
.../config-1.2/log4j-console-HtmlLayout.properties | 2 ++
.../apache/logging/log4j/core/layout/HtmlLayout.java | 14 ++++++++++++++
4 files changed, 26 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bbae0af6/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
index d88a23c..0848f4d 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
@@ -148,10 +148,16 @@ public class Log4j1ConfigurationFactory extends ConfigurationFactory {
break;
}
case "org.apache.log4j.HTMLLayout": {
- appenderBuilder.add(builder.newLayout("HtmlLayout"));
+ LayoutComponentBuilder htmlLayout = builder.newLayout("HtmlLayout");
+ htmlLayout.addAttribute("title",
+ getLog4jAppenderValue(properties, name, "layout.Title", "Log4J Log Messages"));
+ htmlLayout.addAttribute("locationInfo",
+ Boolean.parseBoolean(getLog4jAppenderValue(properties, name, "layout.LocationInfo", "false")));
+ appenderBuilder.add(htmlLayout);
break;
}
case "org.apache.log4j.xml.XMLLayout": {
+ // TODO support properties
appenderBuilder.add(builder.newLayout("Log4j1XmlLayout"));
break;
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bbae0af6/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
index 81eb214..66935cc 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
@@ -60,8 +60,9 @@ public class Log4j1ConfigurationFactoryTest {
@Test
public void testConsoleHtmlLayout() throws Exception {
- final Layout<?> layout = testConsole("config-1.2/log4j-console-HtmlLayout.properties");
- assertTrue(layout instanceof HtmlLayout);
+ final HtmlLayout layout = (HtmlLayout)testConsole("config-1.2/log4j-console-HtmlLayout.properties");
+ assertEquals("Headline", layout.getTitle());
+ assertTrue(layout.isLocationInfo());
}
@Test
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bbae0af6/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-HtmlLayout.properties
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-HtmlLayout.properties b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-HtmlLayout.properties
index decd369..304180c 100644
--- a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-HtmlLayout.properties
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-HtmlLayout.properties
@@ -14,5 +14,7 @@ log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.ImmediateFlush=false
log4j.appender.Console.Target=System.err
log4j.appender.Console.layout=org.apache.log4j.HTMLLayout
+log4j.appender.Console.layout.Title=Headline
+log4j.appender.Console.layout.LocationInfo=true
log4j.logger.com.example.foo = DEBUG
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bbae0af6/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/HtmlLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/HtmlLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/HtmlLayout.java
index e3e60d9..030a402 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/HtmlLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/HtmlLayout.java
@@ -110,6 +110,20 @@ public final class HtmlLayout extends AbstractStringLayout {
this.headerSize = headerSize;
}
+ /**
+ * For testing purposes.
+ */
+ public String getTitle() {
+ return title;
+ }
+
+ /**
+ * For testing purposes.
+ */
+ public boolean isLocationInfo() {
+ return locationInfo;
+ }
+
private String addCharsetToContentType(final String contentType) {
if (contentType == null) {
return DEFAULT_CONTENT_TYPE + "; charset=" + getCharset();