-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure stdout-loglevel setting is honored through the whole actor …
…system lifecycle (#5251) * Make sure stdout-loglevel setting is honored through the whole actor system lifecycle * Add settings spec for the new StandardOutLogger setting * Update API Approver list * Test logger can still output logs * Suppress LoggerInitialized from deadletter * Update API Approver list * Remove LogLevel.OffLevel for backward compatibility * Update API Approver list * Re-add OffLogLevel private const * Fix XML doc and previously hardwired StandardOutLogger type checking. * Add documentation to the new MinimalLogger implementation * Change equality to inheritance check * Add MinimalLogger spec Co-authored-by: Aaron Stannard <aaron@petabridge.com>
- Loading branch information
1 parent
8f168fc
commit 8279ed4
Showing
15 changed files
with
335 additions
and
117 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// //----------------------------------------------------------------------- | ||
// // <copyright file="ShutdownLoggerSpec.cs" company="Akka.NET Project"> | ||
// // Copyright (C) 2009-2021 Lightbend Inc. <http://www.lightbend.com> | ||
// // Copyright (C) 2013-2021 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// // </copyright> | ||
// //----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Akka.Actor; | ||
using Akka.Configuration; | ||
using Akka.Event; | ||
using Akka.TestKit; | ||
using FluentAssertions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Akka.Tests.Loggers | ||
{ | ||
public class ShutdownLoggerSpec: AkkaSpec | ||
{ | ||
private static readonly Config Config = ConfigurationFactory.ParseString(@" | ||
akka.loglevel = OFF | ||
akka.stdout-loglevel = OFF | ||
akka.stdout-logger-class = ""Akka.Tests.Loggers.ThrowingLogger, Akka.Tests"""); | ||
|
||
public ShutdownLoggerSpec(ITestOutputHelper output) : base(Config, output) | ||
{ | ||
} | ||
|
||
[Fact(DisplayName = "StandardOutLogger should not be called on shutdown when stdout-loglevel is set to OFF")] | ||
public async Task StandardOutLoggerShouldNotBeCalled() | ||
{ | ||
Sys.Settings.StdoutLogger.Should().BeOfType<ThrowingLogger>(); | ||
|
||
var probeRef = Sys.ActorOf(Props.Create(() => new LogProbe())); | ||
probeRef.Tell(new InitializeLogger(Sys.EventStream)); | ||
var probe = await probeRef.Ask<LogProbe>("hey"); | ||
|
||
await Sys.Terminate(); | ||
|
||
await Task.Delay(RemainingOrDefault); | ||
if (probe.Events.Any(o => o is Error err && err.Cause is ShutdownLogException)) | ||
throw new Exception("Test failed, log should not be called after shutdown."); | ||
} | ||
} | ||
|
||
internal class LogProbe : ReceiveActor | ||
{ | ||
public List<LogEvent> Events { get; } = new List<LogEvent>(); | ||
|
||
public LogProbe() | ||
{ | ||
Receive<string>(msg => Sender.Tell(this)); | ||
Receive<LogEvent>(Events.Add); | ||
Receive<InitializeLogger>(e => | ||
{ | ||
e.LoggingBus.Subscribe(Self, typeof (LogEvent)); | ||
Sender.Tell(new LoggerInitialized()); | ||
}); | ||
|
||
} | ||
} | ||
|
||
internal class ShutdownLogException : Exception | ||
{ | ||
public ShutdownLogException() | ||
{ } | ||
|
||
public ShutdownLogException(string msg) : base(msg) | ||
{ } | ||
} | ||
|
||
internal class ThrowingLogger : MinimalLogger | ||
{ | ||
protected override void Log(object message) | ||
{ | ||
throw new ShutdownLogException("This logger should never be called."); | ||
} | ||
} | ||
} |
Oops, something went wrong.