logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1210987 - in /logging/log4net/trunk: src/ src/Layout/ tests/src/ tests/src/Layout/
Date Tue, 06 Dec 2011 15:46:54 GMT
Author: bodewig
Date: Tue Dec  6 15:46:53 2011
New Revision: 1210987

URL: http://svn.apache.org/viewvc?rev=1210987&view=rev
Log:
a PaternLayout subclass that re-evaluates header and footer on each call.  Submitted by Roy
Chastain.  LOG4NET-316

Added:
    logging/log4net/trunk/src/Layout/DynamicPatternLayout.cs   (with props)
    logging/log4net/trunk/tests/src/Layout/DynamicPatternLayoutTest.cs   (with props)
Modified:
    logging/log4net/trunk/src/log4net.vs2008.csproj
    logging/log4net/trunk/src/log4net.vs2010.csproj
    logging/log4net/trunk/tests/src/Layout/PatternLayoutTest.cs
    logging/log4net/trunk/tests/src/log4net.Tests.vs2003.csproj
    logging/log4net/trunk/tests/src/log4net.Tests.vs2008.csproj
    logging/log4net/trunk/tests/src/log4net.Tests.vs2010.csproj

Added: logging/log4net/trunk/src/Layout/DynamicPatternLayout.cs
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/Layout/DynamicPatternLayout.cs?rev=1210987&view=auto
==============================================================================
--- logging/log4net/trunk/src/Layout/DynamicPatternLayout.cs (added)
+++ logging/log4net/trunk/src/Layout/DynamicPatternLayout.cs Tue Dec  6 15:46:53 2011
@@ -0,0 +1,143 @@
+#region Apache License
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more 
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership. 
+// The ASF licenses this file to you under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with 
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#endregion
+
+
+using System;
+using System.Collections;
+using System.IO;
+
+using log4net.Core;
+using log4net.Layout.Pattern;
+using log4net.Util;
+
+namespace log4net.Layout
+{
+	/// <summary>
+	/// A flexible layout configurable with pattern string that re-evaluates on each call.
+	/// </summary>
+	/// <remarks>
+	/// <para>This class is built on <see cref="PatternLayout"></see> and
provides all the
+	/// features and capabilities of PatternLayout.  PatternLayout is a 'static' class
+	/// in that its layout is done once at configuration time.  This class will recreate
+	/// the layout on each reference.</para>
+	/// <para>One important difference between PatternLayout and DynamicPatternLayout
is the
+	/// treatment of the Header and Footer parameters in the configuration.  The Header and
Footer
+	/// parameters for DynamicPatternLayout must be syntactically in the form of a PatternString,
+	/// but should not be marked as type log4net.Util.PatternString.  Doing so causes the
+	/// pattern to be statically converted at configuration time and causes DynamicPatternLayout
+	/// to perform the same as PatternLayout.</para>
+	/// <para>Please see <see cref="PatternLayout"/> for complete documentation.</para>
+	/// <example>
+	///	&lt;layout type="log4net.Layout.DynamicPatternLayout"&gt;
+	///   &lt;param name="Header" value="%newline**** Trace Opened     Local: %date{yyyy-MM-dd
HH:mm:ss.fff}     UTC: %utcdate{yyyy-MM-dd HH:mm:ss.fff} ****%newline" /&gt;
+	///   &lt;param name="Footer" value="**** Trace Closed %date{yyyy-MM-dd HH:mm:ss.fff}
****%newline" /&gt;
+	/// &lt;/layout&gt;
+	/// </example>
+	/// </remarks>
+	public class DynamicPatternLayout: PatternLayout
+	{
+		#region Member Variables
+		/// <summary>
+		/// The header PatternString
+		/// </summary>
+		private PatternString m_headerPatternString = new PatternString("");
+
+		/// <summary>
+		/// The footer PatternString
+		/// </summary>
+		private PatternString m_footerPatternString  = new PatternString("");
+		#endregion
+
+		#region Constructors
+		/// <summary>
+		/// Constructs a DynamicPatternLayout using the DefaultConversionPattern
+		/// </summary>
+		/// <remarks>
+		/// <para>
+		/// The default pattern just produces the application supplied message.
+		/// </para>
+		/// </remarks>
+		public DynamicPatternLayout()
+			: base()
+		{
+		}
+
+		/// <summary>
+		/// Constructs a DynamicPatternLayout using the supplied conversion pattern
+		/// </summary>
+		/// <param name="pattern">the pattern to use</param>
+		/// <remarks>
+		/// </remarks>
+		public DynamicPatternLayout (string pattern) 
+			: base(pattern)
+		{
+		}
+		#endregion
+
+		#region Override implementation of LayoutSkeleton
+		/// <summary>
+		/// The header for the layout format.
+		/// </summary>
+		/// <value>the layout header</value>
+		/// <remarks>
+		/// <para>
+		/// The Header text will be appended before any logging events
+		/// are formatted and appended.
+		/// </para>
+		/// The pattern will be formatted on each get operation.
+		/// </remarks>
+		public override string Header
+		{
+			get
+			{
+				return m_headerPatternString.Format();
+			}
+			set
+			{
+				base.Header = value;
+				m_headerPatternString = new PatternString(value);
+			}
+		}		/* property DynamicPatternLayout Header */
+
+		/// <summary>
+		/// The footer for the layout format.
+		/// </summary>
+		/// <value>the layout footer</value>
+		/// <remarks>
+		/// <para>
+		/// The Footer text will be appended after all the logging events
+		/// have been formatted and appended.
+		/// </para>
+		/// The pattern will be formatted on each get operation.
+		/// </remarks>
+		public override string Footer
+		{
+			get
+			{
+				return m_footerPatternString.Format();
+			}
+			set
+			{
+				base.Footer = value;
+				m_footerPatternString = new PatternString(value);
+			}
+		}		/* property DynamicPatternLayout Footer */
+		#endregion
+	}			/* class DynamicPatternLayout */
+}				/* namespace log4net.Layout */

Propchange: logging/log4net/trunk/src/Layout/DynamicPatternLayout.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: logging/log4net/trunk/src/log4net.vs2008.csproj
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/log4net.vs2008.csproj?rev=1210987&r1=1210986&r2=1210987&view=diff
==============================================================================
--- logging/log4net/trunk/src/log4net.vs2008.csproj (original)
+++ logging/log4net/trunk/src/log4net.vs2008.csproj Tue Dec  6 15:46:53 2011
@@ -365,6 +365,9 @@
     <Compile Include="ILog.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="Layout\DynamicPatternLayout.cs">
+      <SubType>Code</SubType>
+    </Compile>
     <Compile Include="Layout\ExceptionLayout.cs">
       <SubType>Code</SubType>
     </Compile>

Modified: logging/log4net/trunk/src/log4net.vs2010.csproj
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/log4net.vs2010.csproj?rev=1210987&r1=1210986&r2=1210987&view=diff
==============================================================================
--- logging/log4net/trunk/src/log4net.vs2010.csproj (original)
+++ logging/log4net/trunk/src/log4net.vs2010.csproj Tue Dec  6 15:46:53 2011
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <!--
 
  Licensed to the Apache Software Foundation (ASF) under one
@@ -381,6 +381,9 @@
     <Compile Include="ILog.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="Layout\DynamicPatternLayout.cs">
+      <SubType>Code</SubType>
+    </Compile>
     <Compile Include="Layout\ExceptionLayout.cs">
       <SubType>Code</SubType>
     </Compile>

Added: logging/log4net/trunk/tests/src/Layout/DynamicPatternLayoutTest.cs
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Layout/DynamicPatternLayoutTest.cs?rev=1210987&view=auto
==============================================================================
--- logging/log4net/trunk/tests/src/Layout/DynamicPatternLayoutTest.cs (added)
+++ logging/log4net/trunk/tests/src/Layout/DynamicPatternLayoutTest.cs Tue Dec  6 15:46:53
2011
@@ -0,0 +1,37 @@
+#region Apache License
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more 
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership. 
+// The ASF licenses this file to you under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with 
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#endregion
+
+using log4net.Layout;
+
+using NUnit.Framework;
+
+namespace log4net.Tests.Layout {
+    /// <summary>
+    /// Used for internal unit testing the <see cref="DynamicPatternLayout"/> class.
+    /// </summary>
+    public class DynamicPatternLayoutTest : PatternLayoutTest {
+        protected override PatternLayout NewPatternLayout() {
+            return new DynamicPatternLayout();
+        }
+
+        protected override PatternLayout NewPatternLayout(string pattern) {
+            return new DynamicPatternLayout(pattern);
+        }
+    }
+}

Propchange: logging/log4net/trunk/tests/src/Layout/DynamicPatternLayoutTest.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: logging/log4net/trunk/tests/src/Layout/PatternLayoutTest.cs
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Layout/PatternLayoutTest.cs?rev=1210987&r1=1210986&r2=1210987&view=diff
==============================================================================
--- logging/log4net/trunk/tests/src/Layout/PatternLayoutTest.cs (original)
+++ logging/log4net/trunk/tests/src/Layout/PatternLayoutTest.cs Tue Dec  6 15:46:53 2011
@@ -47,11 +47,19 @@ namespace log4net.Tests.Layout
             Utils.RemovePropertyFromAllContexts();
         }
 
-		[Test]
+        protected virtual PatternLayout NewPatternLayout() {
+            return new PatternLayout();
+        }
+
+        protected virtual PatternLayout NewPatternLayout(string pattern) {
+            return new PatternLayout(pattern);
+        }
+
+        [Test]
 		public void TestThreadPropertiesPattern()
 		{
 			StringAppender stringAppender = new StringAppender();
-            stringAppender.Layout = new PatternLayout("%property{" + Utils.PROPERTY_KEY +
"}");
+            stringAppender.Layout = NewPatternLayout("%property{" + Utils.PROPERTY_KEY +
"}");
 
 			ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
 			BasicConfigurator.Configure(rep, stringAppender);
@@ -79,7 +87,7 @@ namespace log4net.Tests.Layout
         public void TestStackTracePattern()
         {
             StringAppender stringAppender = new StringAppender();
-            stringAppender.Layout = new PatternLayout("%stacktrace{2}");
+            stringAppender.Layout = NewPatternLayout("%stacktrace{2}");
 
             ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
             BasicConfigurator.Configure(rep, stringAppender);
@@ -99,7 +107,7 @@ namespace log4net.Tests.Layout
 		public void TestGlobalPropertiesPattern()
 		{
 			StringAppender stringAppender = new StringAppender();
-            stringAppender.Layout = new PatternLayout("%property{" + Utils.PROPERTY_KEY +
"}");
+            stringAppender.Layout = NewPatternLayout("%property{" + Utils.PROPERTY_KEY +
"}");
 
 			ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
 			BasicConfigurator.Configure(rep, stringAppender);
@@ -127,7 +135,7 @@ namespace log4net.Tests.Layout
 		public void TestAddingCustomPattern()
 		{
 			StringAppender stringAppender = new StringAppender();
-			PatternLayout layout = new PatternLayout();
+			PatternLayout layout = NewPatternLayout();
 
 			layout.AddConverter("TestAddingCustomPattern", typeof(TestMessagePatternConverter));
 			layout.ConversionPattern = "%TestAddingCustomPattern";
@@ -149,7 +157,7 @@ namespace log4net.Tests.Layout
         public void NamedPatternConverterWithoutPrecisionShouldReturnFullName()
         {
             StringAppender stringAppender = new StringAppender();
-            PatternLayout layout = new PatternLayout();
+            PatternLayout layout = NewPatternLayout();
             layout.AddConverter("message-as-name", typeof(MessageAsNamePatternConverter));
             layout.ConversionPattern = "%message-as-name";
             layout.ActivateOptions();
@@ -196,7 +204,7 @@ namespace log4net.Tests.Layout
         public void NamedPatternConverterWithPrecision1ShouldStripLeadingStuffIfPresent()
         {
             StringAppender stringAppender = new StringAppender();
-            PatternLayout layout = new PatternLayout();
+            PatternLayout layout = NewPatternLayout();
             layout.AddConverter("message-as-name", typeof(MessageAsNamePatternConverter));
             layout.ConversionPattern = "%message-as-name{1}";
             layout.ActivateOptions();
@@ -242,7 +250,7 @@ namespace log4net.Tests.Layout
         [Test]
         public void NamedPatternConverterWithPrecision2ShouldStripLessLeadingStuffIfPresent()
{
             StringAppender stringAppender = new StringAppender();
-            PatternLayout layout = new PatternLayout();
+            PatternLayout layout = NewPatternLayout();
             layout.AddConverter("message-as-name", typeof(MessageAsNamePatternConverter));
             layout.ConversionPattern = "%message-as-name{2}";
             layout.ActivateOptions();
@@ -306,7 +314,7 @@ namespace log4net.Tests.Layout
 		public void TestExceptionPattern()
 		{
 			StringAppender stringAppender = new StringAppender();
-			PatternLayout layout = new PatternLayout("%exception{stacktrace}");
+			PatternLayout layout = NewPatternLayout("%exception{stacktrace}");
 			stringAppender.Layout = layout;
 
 			ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());

Modified: logging/log4net/trunk/tests/src/log4net.Tests.vs2003.csproj
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/log4net.Tests.vs2003.csproj?rev=1210987&r1=1210986&r2=1210987&view=diff
==============================================================================
--- logging/log4net/trunk/tests/src/log4net.Tests.vs2003.csproj (original)
+++ logging/log4net/trunk/tests/src/log4net.Tests.vs2003.csproj Tue Dec  6 15:46:53 2011
@@ -227,6 +227,11 @@
                     BuildAction = "Compile"
                 />
                 <File
+                    RelPath = "Layout\DynamicPatternLayoutTest.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
                     RelPath = "Layout\PatternLayoutTest.cs"
                     SubType = "Code"
                     BuildAction = "Compile"

Modified: logging/log4net/trunk/tests/src/log4net.Tests.vs2008.csproj
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/log4net.Tests.vs2008.csproj?rev=1210987&r1=1210986&r2=1210987&view=diff
==============================================================================
--- logging/log4net/trunk/tests/src/log4net.Tests.vs2008.csproj (original)
+++ logging/log4net/trunk/tests/src/log4net.Tests.vs2008.csproj Tue Dec  6 15:46:53 2011
@@ -164,6 +164,9 @@
     <Compile Include="Hierarchy\Logger.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="Layout\DynamicPatternLayoutTest.cs">
+      <SubType>Code</SubType>
+    </Compile>
     <Compile Include="Layout\PatternLayoutTest.cs">
       <SubType>Code</SubType>
     </Compile>

Modified: logging/log4net/trunk/tests/src/log4net.Tests.vs2010.csproj
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/log4net.Tests.vs2010.csproj?rev=1210987&r1=1210986&r2=1210987&view=diff
==============================================================================
--- logging/log4net/trunk/tests/src/log4net.Tests.vs2010.csproj (original)
+++ logging/log4net/trunk/tests/src/log4net.Tests.vs2010.csproj Tue Dec  6 15:46:53 2011
@@ -181,6 +181,7 @@
     <Compile Include="Hierarchy\Logger.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="Layout\DynamicPatternLayoutTest.cs" />
     <Compile Include="Layout\PatternLayoutTest.cs">
       <SubType>Code</SubType>
     </Compile>



Mime
View raw message