Skip to content

Commit

Permalink
* fix mismatched log level for the Primary Drawing Order message
Browse files Browse the repository at this point in the history
* commission separate list of prefixes for filtering original warnings
* unit test
  • Loading branch information
eduard-dumitru committed Dec 6, 2023
1 parent 4a340e8 commit e85a079
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
15 changes: 13 additions & 2 deletions UiPath.FreeRdpClient/UiPath.FreeRdpClient.Tests/LoggingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public async Task ErrorLogsShouldBeFilteredAndTranslatedToWarn()
{
var forwarder = Host.GetRequiredService<NativeLoggingForwarder>();
forwarder.FilterRemoveStartsWith = new[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString() };
forwarder.FilterRemoveStartsWithWarnings = new[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString() };

var someTestCategory = Guid.NewGuid().ToString();
var testLogs = _logsByCategory.Where(kv => kv.Key == someTestCategory)
Expand All @@ -115,16 +116,26 @@ public async Task ErrorLogsShouldBeFilteredAndTranslatedToWarn()
forwarder.LogCallbackDelegate(someTestCategory, LogLevel.Error, startWith + "_extra2");
forwarder.LogCallbackDelegate(someTestCategory, LogLevel.Error, startWith);
}
foreach (var startWith in forwarder.FilterRemoveStartsWithWarnings)
{
forwarder.LogCallbackDelegate(someTestCategory, LogLevel.Warning, startWith + "_extra1");
forwarder.LogCallbackDelegate(someTestCategory, LogLevel.Warning, startWith + "_extra2");
forwarder.LogCallbackDelegate(someTestCategory, LogLevel.Warning, startWith);
}
testLogs.ShouldBeEmpty();

foreach (var startWith in forwarder.FilterRemoveStartsWith)
{
forwarder.LogCallbackDelegate(someTestCategory, LogLevel.Error, "_" + startWith);
}
foreach (var startWith in forwarder.FilterRemoveStartsWithWarnings)
{
forwarder.LogCallbackDelegate(someTestCategory, LogLevel.Warning, "_" + startWith);
}
testLogs.Count()
.ShouldBe(forwarder.FilterRemoveStartsWith.Length);
.ShouldBe(forwarder.FilterRemoveStartsWith.Length + forwarder.FilterRemoveStartsWithWarnings.Length);
testLogs.Count(l => l.logLevel is LogLevel.Warning)
.ShouldBe(forwarder.FilterRemoveStartsWith.Length);
.ShouldBe(forwarder.FilterRemoveStartsWith.Length + forwarder.FilterRemoveStartsWithWarnings.Length);
testLogs.Where(l => l.logLevel is LogLevel.Error)
.ShouldBeEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ internal sealed class NativeLoggingForwarder : IDisposable
"history buffer index out of range",//10+
"history buffer overflow",
"fastpath_recv_update() - -1",
"Primary Drawing Order"
};

public string[] FilterRemoveStartsWithWarnings = new[]
{
"Primary Drawing Order",
};

public NativeLoggingForwarder(ILoggerFactory loggerFactory)
Expand Down Expand Up @@ -73,7 +77,11 @@ private void RegisterThreadScope(string scope)
private bool FilterLogs(LogLevel logLevel, string message)
{
if (logLevel is LogLevel.Error
&& FilterRemoveStartsWith.Any(message.StartsWith))
&& Array.Exists(FilterRemoveStartsWith, message.StartsWith))
return false;

if (logLevel is LogLevel.Warning
&& Array.Exists(FilterRemoveStartsWithWarnings, message.StartsWith))
return false;

return true;
Expand Down

0 comments on commit e85a079

Please sign in to comment.