Skip to content

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

Merged
Aaronontheweb merged 24 commits into
akkadotnet:devfrom
Arkatufus:Add_new_StandardOutLogger_features
Sep 8, 2021
Merged

Aaronontheweb merged 24 commits into
akkadotnet:devfrom
Arkatufus:Add_new_StandardOutLogger_features

Conversation

@Arkatufus

@Arkatufus Arkatufus commented Sep 3, 2021 •

Copy link
Copy Markdown
Contributor

Closes #5246

{
try
{
_output.WriteLine(e.ToString());

Copy link
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

/// <returns>TBD</returns>
protected override bool Receive(object message)
{
if(message is InitializeLogger)

Copy link
Copy Markdown
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

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

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread src/core/Akka/Event/LogLevel.cs Outdated
/// <summary>
/// The off log level.
/// </summary>
OffLevel = int.MaxValue

Copy link
Copy Markdown
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
Copy Markdown
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.


namespace Akka.Event
{
public abstract class MinimalLogger : MinimalActorRef

Copy link
Copy Markdown
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
Copy Markdown
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 left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

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

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

Copy link
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

/// 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
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Comment thread src/core/Akka/Event/LogLevel.cs Outdated
/// <summary>
/// The off log level.
/// </summary>
OffLevel = int.MaxValue

Copy link
Copy Markdown
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.

@Aaronontheweb Aaronontheweb left a comment

Copy link
Copy Markdown
Member

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

case LogLevel.ErrorLevel:
return Error;
case OffLogLevel:
return Off;

Copy link
Copy Markdown
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

Comment thread src/core/Akka/Event/Logging.cs
Comment thread src/core/Akka/Event/Logging.cs Outdated
return LogLevel.ErrorLevel;
case Off:
return OffLogLevel;
return (LogLevel) int.MaxValue;

Copy link
Copy Markdown
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

/// </summary>
/// <param name="logEvent">The event to print</param>
public static void PrintLogEvent(LogEvent logEvent)
internal static void PrintLogEvent(LogEvent logEvent)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good call

@Aaronontheweb Aaronontheweb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM


namespace Akka.Event
{
public abstract class MinimalLogger : MinimalActorRef

Copy link
Copy Markdown
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
Arkatufus disabled auto-merge September 6, 2021 19:51
@Arkatufus

Arkatufus commented Sep 6, 2021 •

Copy link
Copy Markdown
Contributor Author

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

@Arkatufus

Copy link
Copy Markdown
Contributor Author

Done, documentation added.

@Arkatufus

Copy link
Copy Markdown
Contributor Author

Should be ready for review now

@Aaronontheweb Aaronontheweb left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
{
var logLevel = Logging.LogLevelFor(config.StdoutLogLevel);
SubscribeLogLevelAndAbove(logLevel, Logging.StandardOutLogger);
SubscribeLogLevelAndAbove(logLevel, config.StdoutLogger);

Copy link
Copy Markdown
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?

@Arkatufus Arkatufus Sep 15, 2021 •

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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.

@Arkatufus Arkatufus Sep 15, 2021 •

Copy link
Copy Markdown
Contributor Author

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