This is an automated email from the ASF dual-hosted git repository.
ptupitsyn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new d139861141b IGNITE-18887 .NET: Fix TestContextLogger and ConsoleLogger
to include exception details (#10560)
d139861141b is described below
commit d139861141b1d6b0b96504fed80c5bd07ebeefdb
Author: Pavel Tupitsyn <[email protected]>
AuthorDate: Thu Feb 23 16:32:00 2023 +0300
IGNITE-18887 .NET: Fix TestContextLogger and ConsoleLogger to include
exception details (#10560)
Do not omit nativeErrorInfo, it can contain important details from Java
stack trace.
---
.../Log/ConsoleLoggerTest.cs | 10 +++++--
.../dotnet/Apache.Ignite.Core.Tests/TestUtils.cs | 34 +++++++++++++++++++---
.../dotnet/Apache.Ignite.Core/Log/ConsoleLogger.cs | 7 ++++-
3 files changed, 43 insertions(+), 8 deletions(-)
diff --git
a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/ConsoleLoggerTest.cs
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/ConsoleLoggerTest.cs
index 73f9268922e..ebe463fa73d 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/ConsoleLoggerTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/ConsoleLoggerTest.cs
@@ -78,10 +78,14 @@ namespace Apache.Ignite.Core.Tests.Log
logger.Warn("warn!");
logger.Error(new IgniteException("ex!"), "err!");
logger.Trace("trace (ignored)");
+ logger.Log(LogLevel.Debug, "dbg1", null, null, "c1",
"java-err-details", new Exception("ex1"));
- var expectedLog = string.Format("[04:05:06] [Warn] [my-cat]
warn!{0}[04:05:06] [Error] [my-cat] err! " +
- "(exception:
Apache.Ignite.Core.Common.IgniteException: ex!){0}",
+ var expectedLog = string.Format("[04:05:06] [Warn] [my-cat]
warn!{0}" +
+ "[04:05:06] [Error] [my-cat]
err! " +
+ "(exception:
Apache.Ignite.Core.Common.IgniteException: ex!){0}" +
+ "[04:05:06] [Debug] [c1] dbg1
(exception: System.Exception: ex1) (native error: java-err-details){0}",
Environment.NewLine);
+
Assert.AreEqual(expectedLog, writer.ToString());
}
finally
@@ -90,4 +94,4 @@ namespace Apache.Ignite.Core.Tests.Log
}
}
}
-}
\ No newline at end of file
+}
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs
index 4ec057d513d..e0516729edc 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs
@@ -27,6 +27,7 @@ namespace Apache.Ignite.Core.Tests
using System.IO;
using System.Linq;
using System.Reflection;
+ using System.Text;
using System.Threading;
using Apache.Ignite.Core.Binary;
using Apache.Ignite.Core.Cache.Affinity;
@@ -712,11 +713,36 @@ namespace Apache.Ignite.Core.Tests
return;
}
- var text = args != null
- ? string.Format(formatProvider ??
CultureInfo.InvariantCulture, message, args)
- : message;
+ var sb = new StringBuilder();
- _listener.TestOutput(new TestOutput(text +
Environment.NewLine, "Progress", _ctx.CurrentTest?.Id,
_ctx.CurrentTest?.FullName));
+ if (args != null)
+ {
+ sb.AppendFormat(formatProvider ??
CultureInfo.InvariantCulture, message, args);
+ }
+ else
+ {
+ sb.Append(message);
+ }
+
+ if (nativeErrorInfo != null)
+ {
+ sb.Append(Environment.NewLine).Append(nativeErrorInfo);
+ }
+
+ if (ex != null)
+ {
+ sb.Append(Environment.NewLine).Append(ex);
+ }
+
+ sb.Append(Environment.NewLine);
+
+ var output = new TestOutput(
+ text: sb.ToString(),
+ stream: "Progress",
+ testId: _ctx.CurrentTest?.Id,
+ testName: _ctx.CurrentTest?.FullName);
+
+ _listener.TestOutput(output);
}
/** <inheritdoc /> */
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Log/ConsoleLogger.cs
b/modules/platforms/dotnet/Apache.Ignite.Core/Log/ConsoleLogger.cs
index 16434260129..0787626c08d 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Log/ConsoleLogger.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Log/ConsoleLogger.cs
@@ -86,6 +86,11 @@ namespace Apache.Ignite.Core.Log
sb.AppendFormat(" (exception: {0})", ex);
}
+ if (nativeErrorInfo != null)
+ {
+ sb.AppendFormat(" (native error: {0})", nativeErrorInfo);
+ }
+
Console.WriteLine(sb.ToString());
}
@@ -99,4 +104,4 @@ namespace Apache.Ignite.Core.Log
return level >= MinLevel;
}
}
-}
\ No newline at end of file
+}