Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implemented configurable `ILogMessageFormatter` * integrated centralized formatter into `BugLogging` * API approvals * updated documentation to include setting * fixed incomplete documentation * fixed documentation * restored old serilog issues --------- Co-authored-by: Gregorius Soedharmo <arkatufus@yahoo.com>
- Loading branch information
1 parent
bf3b5e2
commit e8e3569
Showing
14 changed files
with
230 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="CustomLogFormatterSpec.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2009-2023 Lightbend Inc. <http://www.lightbend.com> | ||
// Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Akka.Configuration; | ||
using Akka.Event; | ||
using Akka.TestKit; | ||
using FluentAssertions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Akka.Tests.Loggers | ||
{ | ||
public class CustomLogFormatterSpec : AkkaSpec | ||
{ | ||
// <CustomLogFormatter> | ||
private class CustomLogFormatter : ILogMessageFormatter | ||
{ | ||
public string Format(string format, params object[] args) | ||
{ | ||
return string.Format("Custom: " + format, args); | ||
} | ||
|
||
public string Format(string format, IEnumerable<object> args) | ||
{ | ||
return string.Format("Custom: " + format, args.ToArray()); | ||
} | ||
} | ||
// </CustomLogFormatter> | ||
|
||
// <CustomLogFormatterConfig> | ||
public static readonly Config Configuration = "akka.logger-formatter = \"Akka.Tests.Loggers.CustomLogFormatterSpec+CustomLogFormatter, Akka.Tests\""; | ||
// </CustomLogFormatterConfig> | ||
|
||
public CustomLogFormatterSpec(ITestOutputHelper output) : base(Configuration, output) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldUseValidCustomLogFormatter() | ||
{ | ||
// arrange | ||
var probe = CreateTestProbe(); | ||
Sys.EventStream.Subscribe(probe.Ref, typeof(Error)); | ||
|
||
// act | ||
Sys.Log.Error("This is a test {0}", 1); // formatters aren't used when we're logging const strings | ||
|
||
// assert | ||
var msg = await probe.ExpectMsgAsync<Error>(); | ||
msg.Message.Should().BeAssignableTo<LogMessage>(); | ||
msg.ToString().Should().Contain("Custom: This is a test 1"); | ||
|
||
await EventFilter.Error(contains: "Custom").ExpectOneAsync(() => | ||
{ | ||
Sys.Log.Error("This is a test {0}", 1); | ||
return Task.CompletedTask; | ||
}); | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldDetectCustomLogFormatterOutputInEventFilter() | ||
{ | ||
// the EventFilter filters on fully formatted output | ||
await EventFilter.Error(contains: "Custom").ExpectOneAsync(() => | ||
{ | ||
Sys.Log.Error("This is a test {0}", 1); | ||
return Task.CompletedTask; | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.