Skip to content

Commit

Permalink
Fix LogLevels for LoggingContextDecorator (#1602)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeralsing authored May 25, 2022
1 parent ebf1afa commit 0bbe5ed
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/Proto.Actor/Context/ActorLoggingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override async Task Receive(MessageEnvelope envelope)

var logLevel = GetLogLevel(message);

if (_logger.IsEnabled(logLevel))
if (logLevel != LogLevel.None && _logger.IsEnabled(logLevel))
{
_logger.Log(logLevel, "Actor {Self} {ActorType} received message {MessageType}:{Message} from {Sender}", Self, ActorType, message.GetType().Name,
message,
Expand All @@ -63,7 +63,7 @@ public override async Task Receive(MessageEnvelope envelope)
{
await base.Receive(envelope);

if (_logger.IsEnabled(logLevel))
if (logLevel != LogLevel.None && _logger.IsEnabled(logLevel))
{
_logger.Log(logLevel, "Actor {Self} {ActorType} completed message {MessageType}:{Message} from {Sender}", Self, ActorType,
message.GetType().Name,
Expand All @@ -74,7 +74,7 @@ public override async Task Receive(MessageEnvelope envelope)
}
catch (Exception x)
{
if (_logger.IsEnabled(_exceptionLogLevel))
if (_exceptionLogLevel != LogLevel.None && _logger.IsEnabled(_exceptionLogLevel))
{
_logger.Log(_exceptionLogLevel, x, "Actor {Self} {ActorType} failed during message {MessageType}:{Message} from {Sender}", Self, ActorType,
message.GetType().Name, message,
Expand All @@ -88,7 +88,7 @@ public override async Task Receive(MessageEnvelope envelope)

public override void ReenterAfter<T>(Task<T> target, Func<Task<T>, Task> action)
{
if (_logger.IsEnabled(_logLevel))
if (_logLevel != LogLevel.None && _logger.IsEnabled(_logLevel))
{
_logger.Log(_logLevel, "Actor {Self} {ActorType} ReenterAfter {Action}", Self, ActorType, action.Method.Name);
}
Expand All @@ -97,7 +97,7 @@ public override void ReenterAfter<T>(Task<T> target, Func<Task<T>, Task> action)

public override void ReenterAfter(Task target, Action action)
{
if (_logger.IsEnabled(_logLevel))
if (_logLevel != LogLevel.None && _logger.IsEnabled(_logLevel))
{
_logger.Log(_logLevel, "Actor {Self} {ActorType} ReenterAfter {Action}", Self, ActorType, action.Method.Name);
}
Expand All @@ -106,7 +106,7 @@ public override void ReenterAfter(Task target, Action action)

public override async Task<T> RequestAsync<T>(PID target, object message, CancellationToken cancellationToken)
{
if (_logger.IsEnabled(_logLevel))
if (_logLevel != LogLevel.None && _logger.IsEnabled(_logLevel))
{
_logger.Log(_logLevel, "Actor {Self} {ActorType} Sending ReqeustAsync {MessageType}:{Message} to {Target}", Self, ActorType,
message.GetType().Name, message, target
Expand All @@ -117,7 +117,7 @@ public override async Task<T> RequestAsync<T>(PID target, object message, Cancel
{
var response = await base.RequestAsync<T>(target, message, cancellationToken);

if (_logger.IsEnabled(_logLevel))
if (_logLevel != LogLevel.None && _logger.IsEnabled(_logLevel))
{
_logger.Log(_logLevel, "Actor {Self} {ActorType} Got response {Response} to {MessageType}:{Message} from {Target}", Self,
ActorType,
Expand All @@ -129,7 +129,7 @@ public override async Task<T> RequestAsync<T>(PID target, object message, Cancel
}
catch (Exception x)
{
if (_logger.IsEnabled(_exceptionLogLevel))
if (_exceptionLogLevel != LogLevel.None && _logger.IsEnabled(_exceptionLogLevel))
{
_logger.Log(_exceptionLogLevel, x,
"Actor {Self} {ActorType} Got exception waiting for RequestAsync response of {MessageType}:{Message} from {Target}", Self,
Expand Down Expand Up @@ -157,7 +157,7 @@ public override PID SpawnNamed(Props props, string name)
{
var pid = base.SpawnNamed(props, name);

if (_logger.IsEnabled(_logLevel))
if (_logLevel != LogLevel.None && _logger.IsEnabled(_logLevel))
{
_logger.Log(_logLevel, "Actor {Self} {ActorType} Spawned child actor {Name} with PID {Pid}", Self, ActorType, name, pid
);
Expand All @@ -167,7 +167,7 @@ public override PID SpawnNamed(Props props, string name)
}
catch (Exception x)
{
if (_logger.IsEnabled(_exceptionLogLevel))
if (_exceptionLogLevel != LogLevel.None && _logger.IsEnabled(_exceptionLogLevel))
{
_logger.Log(_exceptionLogLevel, x, "Actor {Self} {ActorType} failed when spawning child actor {Name}", Self, ActorType, name);
}
Expand All @@ -180,7 +180,7 @@ public override void Respond(object message)
{
var logLevel = GetLogLevel(message);

if (_logger.IsEnabled(logLevel))
if (logLevel != LogLevel.None && _logger.IsEnabled(logLevel))
{
_logger.Log(logLevel, "Actor {Self} {ActorType} responded with {MessageType}:{Message} to {Sender}", Self, ActorType,
message.GetType().Name, message, Sender
Expand Down

0 comments on commit 0bbe5ed

Please sign in to comment.