-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Customizable ILogMessageFormatter
across entire ActorSystem
#6413
Changes from all commits
997b672
1b7b2c0
33c16b0
e98d73c
98f5a83
83ab5bb
9e3a244
d785c1b
da24939
a80917b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1720,6 +1720,7 @@ namespace Akka.Actor | |
public int LogDeadLetters { get; } | ||
public bool LogDeadLettersDuringShutdown { get; } | ||
public System.TimeSpan LogDeadLettersSuspendDuration { get; } | ||
public Akka.Event.ILogMessageFormatter LogFormatter { get; } | ||
public string LogLevel { get; } | ||
public bool LogSerializerOverrideOnStart { get; } | ||
public bool LoggerAsyncStart { get; } | ||
|
@@ -3000,7 +3001,7 @@ namespace Akka.Event | |
public Akka.Actor.IActorRef Sender { get; } | ||
public override string ToString() { } | ||
} | ||
public class BusLogging : Akka.Event.LoggingAdapterBase | ||
public sealed class BusLogging : Akka.Event.LoggingAdapterBase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
public BusLogging(Akka.Event.LoggingBus bus, string logSource, System.Type logClass, Akka.Event.ILogMessageFormatter logMessageFormatter) { } | ||
public override bool IsDebugEnabled { get; } | ||
|
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validates that custom |
||
{ | ||
// 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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validates that the TestKit's |
||
{ | ||
// 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; | ||
}); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exposed the
ILogMessageFormatter
on theSettings
class.