Skip to content
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

Make sure stdout-loglevel setting is honored through the whole actor system lifecycle #5251

Merged

Conversation

Arkatufus
Copy link
Contributor

@Arkatufus Arkatufus commented Sep 3, 2021

Closes #5246

{
try
{
_output.WriteLine(e.ToString());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add missing format exception catcher to Akka.TestKit.Xunit that was added to Akka.TestKit.Xunit2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -30,57 +30,65 @@ public class TestEventListener : DefaultLogger
/// <returns>TBD</returns>
protected override bool Receive(object message)
{
if(message is InitializeLogger)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change if...then...else structure to switch

@@ -109,6 +110,31 @@ public Settings(ActorSystem system, Config config, ActorSystemSetup setup)

LogLevel = Config.GetString("akka.loglevel", null);
StdoutLogLevel = Config.GetString("akka.stdout-loglevel", null);

var stdoutClassName = Config.GetString("akka.stdout-logger-class", null);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the hard-wired StandardOutLogger instance from the Logging class to the Settings class.
Default StandardOutLogger is now customizable through the HOCON configuration

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this was @zbynek001's suggestion in one of those threads - we should document this inside https://getakka.net/articles/utilities/logging.html#standard-loggers


# Fully qualified class name (FQCN) of the very basic logger used on startup and shutdown.
# You can substitute the logger by supplying an FQCN to a custom class that implements Akka.Event.MinimumLogger
stdout-logger-class = "Akka.Event.StandardOutLogger"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New HOCON setting to customize the standard out logger

/// <summary>
/// The off log level.
/// </summary>
OffLevel = int.MaxValue
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added OffLevel to LogLevel enum, this would act as a marker for the off state

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd revert this change - it's a major part of the public API and will require an update to all downstream loggers probably.

@@ -13,6 +13,38 @@

namespace Akka.Event
{
public abstract class MinimalLogger : MinimalActorRef
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MinimalLogger is the abstract base class for implementing minimal loggers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a separate PR, we should add some documentation for this

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably leave the LogLevel enum alone - as that's a pretty viral change without much benefit, but other than that this PR looks good. Need to add some documentation as well.

{
try
{
_output.WriteLine(e.ToString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}

[Fact(DisplayName = "StandardOutLogger should not be called on shutdown when stdout-loglevel is set to OFF")]
public async Task StandardOutLoggerShouldNotBeCalled()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -109,6 +110,31 @@ public Settings(ActorSystem system, Config config, ActorSystemSetup setup)

LogLevel = Config.GetString("akka.loglevel", null);
StdoutLogLevel = Config.GetString("akka.stdout-loglevel", null);

var stdoutClassName = Config.GetString("akka.stdout-logger-class", null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this was @zbynek001's suggestion in one of those threads - we should document this inside https://getakka.net/articles/utilities/logging.html#standard-loggers

}
catch (MissingMethodException)
{
throw new MissingMethodException(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -12,7 +12,7 @@ namespace Akka.Event
/// <summary>
/// This class represents a message used to notify subscribers that a logger has been initialized.
/// </summary>
public class LoggerInitialized : INoSerializationVerificationNeeded
public class LoggerInitialized : INoSerializationVerificationNeeded, IDeadLetterSuppression
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

/// <summary>
/// The off log level.
/// </summary>
OffLevel = int.MaxValue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd revert this change - it's a major part of the public API and will require an update to all downstream loggers probably.

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more cleanup needed to undo the LogLevel.Off change

@@ -193,8 +187,6 @@ public static string StringFor(this LogLevel logLevel)
return Warning;
case LogLevel.ErrorLevel:
return Error;
case OffLogLevel:
return Off;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add this back

src/core/Akka/Event/Logging.cs Show resolved Hide resolved
@@ -284,7 +276,7 @@ public static LogLevel LogLevelFor(string logLevel)
case Error:
return LogLevel.ErrorLevel;
case Off:
return OffLogLevel;
return (LogLevel) int.MaxValue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add back previous call

@@ -107,7 +119,7 @@ protected override void TellInternal(object message, IActorRef sender)
/// Prints a specified event to the console.
/// </summary>
/// <param name="logEvent">The event to print</param>
public static void PrintLogEvent(LogEvent logEvent)
internal static void PrintLogEvent(LogEvent logEvent)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -13,6 +13,38 @@

namespace Akka.Event
{
public abstract class MinimalLogger : MinimalActorRef
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a separate PR, we should add some documentation for this

@Aaronontheweb Aaronontheweb enabled auto-merge (squash) September 6, 2021 16:00
@Arkatufus
Copy link
Contributor Author

Arkatufus commented Sep 6, 2021

Don't merge just yet, I just spotted a few problems that needs to be changed, plus the documentation.

@Arkatufus
Copy link
Contributor Author

Done, documentation added.

@Arkatufus
Copy link
Contributor Author

Should be ready for review now

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

`akka.stdout-loglevel` HOCON settings to `OFF` if you do not need these feature in your application.

### Advanced MinimalLogger Setup
You can also replace `StandardOutLogger` by making your own logger class with an empty constructor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need to do more showing rather than telling here, but this is good for now

@Aaronontheweb Aaronontheweb merged commit 8279ed4 into akkadotnet:dev Sep 8, 2021
@@ -226,7 +226,7 @@ public void StartStdoutLogger(Settings config)
private void SetUpStdoutLogger(Settings config)
{
var logLevel = Logging.LogLevelFor(config.StdoutLogLevel);
SubscribeLogLevelAndAbove(logLevel, Logging.StandardOutLogger);
SubscribeLogLevelAndAbove(logLevel, config.StdoutLogger);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line change is what PR title says, right?
Before change in this line (229) akka.stdout-loglevel wasn't honored and now, after this line has changed, it is honored, so off means off even during shutdown, right?

Copy link
Contributor Author

@Arkatufus Arkatufus Sep 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, when you set stdout-loglevel to off, nothing will be outputted by the StandardOutLogger, correct.

/// </summary>
/// <param name="config">The configuration used to configure the <see cref="StandardOutLogger"/>.</param>
/// <param name="config">The configuration used to configure the <see cref="MinimalLogger"/>.</param>
public void StartStdoutLogger(Settings config)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I get it right, it's a bit misleading, that if you set your own MinimalLogger then you need to configure it's logging level through akka.stdout-loglevel not for example akka.minimallogger-loglevel.

Copy link
Contributor Author

@Arkatufus Arkatufus Sep 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StandardOutLogger derives from MinimalLogger, it is the barest minimum logger used to log how the system behave without actual loggers running, ie. a logger to log the loggers themselves, it runs at the very start and the very end of the ActorSystem life cycle. The only thing you can make by inheriting MinimalLogger is a replacement for the StandardOutLogger, thus it will use the same settings as StandardOutLogger.

You would never do this under normal circumstances, it is considered as an advanced configuration/customization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Akka.Actor: need to enforce stdout-loglevel = off all the way through ActorSystem lifecycle
3 participants