You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by fr...@apache.org on 2025/08/25 14:46:06 UTC

(logging-log4net) branch Feature/shorten-console-output-for-unit-tests created (now c839b8ef)

This is an automated email from the ASF dual-hosted git repository.

freeandnil pushed a change to branch Feature/shorten-console-output-for-unit-tests
in repository https://gitbox.apache.org/repos/asf/logging-log4net.git


      at c839b8ef shorten console output for unit tests

This branch includes the following new commits:

     new c839b8ef shorten console output for unit tests

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(logging-log4net) 01/01: shorten console output for unit tests

Posted by fr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

freeandnil pushed a commit to branch Feature/shorten-console-output-for-unit-tests
in repository https://gitbox.apache.org/repos/asf/logging-log4net.git

commit c839b8ef218d98d1f21d83d21a2493d53795b2cb
Author: Jan Friedrich <fr...@apache.org>
AuthorDate: Mon Aug 25 16:45:47 2025 +0200

    shorten console output for unit tests
---
 src/changelog/3.2.1/267-shorten-test-output.xml | 10 +++++++++
 src/log4net.Tests/Util/LogLogTest.cs            | 27 +++++++++++++++++++++----
 src/log4net/Util/LogLog.cs                      | 21 ++++++++++++++++++-
 3 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/src/changelog/3.2.1/267-shorten-test-output.xml b/src/changelog/3.2.1/267-shorten-test-output.xml
new file mode 100644
index 00000000..549b7b1a
--- /dev/null
+++ b/src/changelog/3.2.1/267-shorten-test-output.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns="https://logging.apache.org/xml/ns"
+       xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
+       type="fixed">
+  <issue id="267" link="https://github.com/apache/logging-log4net/pull/267"/>
+  <description format="asciidoc">
+    shorten console output for unit tests (by @FreeAndNil in https://github.com/apache/logging-log4net/pull/267[#267])
+  </description>
+</entry>
\ No newline at end of file
diff --git a/src/log4net.Tests/Util/LogLogTest.cs b/src/log4net.Tests/Util/LogLogTest.cs
index 3cde0e3b..94acb385 100644
--- a/src/log4net.Tests/Util/LogLogTest.cs
+++ b/src/log4net.Tests/Util/LogLogTest.cs
@@ -32,6 +32,9 @@ namespace log4net.Tests.Util;
 [TestFixture]
 public class LogLogTest
 {
+  /// <summary>
+  /// Tests the <see cref="TraceListener"/> functionality
+  /// </summary>
   [Test]
   public void TraceListenerCounterTest()
   {
@@ -46,6 +49,9 @@ public void TraceListenerCounterTest()
     Assert.That(listTraceListener.Count, Is.EqualTo(2));
   }
 
+  /// <summary>
+  /// Tests the <see cref="LogLog.EmitInternalMessages"/> property
+  /// </summary>
   [Test]
   public void EmitInternalMessages()
   {
@@ -71,6 +77,9 @@ public void EmitInternalMessages()
     }
   }
 
+  /// <summary>
+  /// Tests the <see cref="LogLog.LogReceivedAdapter"/> class.
+  /// </summary>
   [Test]
   public void LogReceivedAdapter()
   {
@@ -90,10 +99,13 @@ public void LogReceivedAdapter()
   [Test]
   public void LogReceivedAdapterThreading()
   {
-    for (int i = 0; i < 1000; i++)
+    LogLog.ExecuteWithoutEmittingInternalMessages(() =>
     {
-      LogReceivedAdapterThreadingCore(i);
-    }
+      for (int i = 0; i < 1000; i++)
+      {
+        LogReceivedAdapterThreadingCore(i);
+      }
+    });
   }
 
   [System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA5394:Do not use insecure randomness", 
@@ -119,13 +131,20 @@ private void LogReceivedAdapterThreadingCore(int seed)
   }
 }
 
+/// <summary>
+/// Mock for <see cref="TraceListener"/> that counts the number of calls to <see cref="Write(string?)"/>
+/// </summary>
 internal sealed class TraceListenerCounter : TraceListener
 {
+  /// <inheritdoc/>
   public override void Write(string? message) => Count++;
 
+  /// <inheritdoc/>
   public override void WriteLine(string? message) => Write(message);
 
+  /// <inheritdoc/>
   public void Reset() => Count = 0;
 
+  /// <inheritdoc/>
   public int Count { get; private set; }
-}
+}
\ No newline at end of file
diff --git a/src/log4net/Util/LogLog.cs b/src/log4net/Util/LogLog.cs
index f5f3c607..121bb4b3 100644
--- a/src/log4net/Util/LogLog.cs
+++ b/src/log4net/Util/LogLog.cs
@@ -223,10 +223,29 @@ static LogLog()
   public static bool QuietMode { get; set; }
 
   /// <summary>
-  /// 
+  /// Configures whether internal messages are emitted to Console.Out and Console.Error.
   /// </summary>
   public static bool EmitInternalMessages { get; set; } = true;
 
+  /// <summary>
+  /// Execute the callback with internal messages suppressed
+  /// </summary>
+  /// <param name="callback">Callback</param>
+  public static void ExecuteWithoutEmittingInternalMessages(Action callback)
+  {
+    callback.EnsureNotNull();
+    bool oldEmitInternalMessages = EmitInternalMessages;
+    EmitInternalMessages = false;
+    try
+    {
+      callback();
+    }
+    finally
+    {
+      EmitInternalMessages = oldEmitInternalMessages;
+    }
+  }
+
   /// <summary>
   /// Raises the LogReceived event when an internal messages is received.
   /// </summary>