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

Unify akka logs with neo logs #1623

Merged
merged 9 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/neo/LogLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ namespace Neo
{
public enum LogLevel : byte
{
Fatal,
Error,
Warning,
Info,
Debug
Debug = 0,
Info = 1,
Warning = 2,
Error = 3,
Fatal = 4
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
}
}
2 changes: 1 addition & 1 deletion src/neo/NeoSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Neo
public class NeoSystem : IDisposable
{
public ActorSystem ActorSystem { get; } = ActorSystem.Create(nameof(NeoSystem),
$"akka {{ log-dead-letters = off }}" +
$"akka {{ log-dead-letters = off , loglevel = warning, loggers = [ \"{typeof(Utility.Logger).AssemblyQualifiedName}\" ] }}" +
$"blockchain-mailbox {{ mailbox-type: \"{typeof(BlockchainMailbox).AssemblyQualifiedName}\" }}" +
$"task-manager-mailbox {{ mailbox-type: \"{typeof(TaskManagerMailbox).AssemblyQualifiedName}\" }}" +
$"remote-node-mailbox {{ mailbox-type: \"{typeof(RemoteNodeMailbox).AssemblyQualifiedName}\" }}" +
Expand Down
4 changes: 2 additions & 2 deletions src/neo/Plugins/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEven
}
catch (Exception ex)
{
Utility.Log(nameof(Plugin), LogLevel.Error, $"Failed to resolve assembly or its dependency: {ex.Message}");
Utility.Log(an.Name, LogLevel.Error, $"Failed to resolve assembly or its dependency: {ex.Message}");
shargon marked this conversation as resolved.
Show resolved Hide resolved
return null;
}
}
Expand Down Expand Up @@ -137,7 +137,7 @@ private static void LoadPlugin(Assembly assembly)
}
catch (Exception ex)
{
Utility.Log(nameof(Plugin), LogLevel.Error, $"Failed to initialize plugin: {ex.Message}");
Utility.Log(type.Name, LogLevel.Error, $"Failed to initialize plugin: {ex.Message}");
shargon marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/neo/Utility.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Akka.Actor;
using Akka.Event;
using Microsoft.Extensions.Configuration;
using Neo.Plugins;
using System;
Expand All @@ -6,6 +8,28 @@ namespace Neo
{
public static class Utility
{
internal class Logger : ReceiveActor
{
public Logger()
{
Receive<Debug>(e => OnLog(LogLevel.Debug, e.ToString()));
Receive<Info>(e => OnLog(LogLevel.Info, e.ToString()));
Receive<Warning>(e => OnLog(LogLevel.Warning, e.ToString()));
Receive<Error>(e => OnLog(LogLevel.Error, e.ToString()));
Receive<InitializeLogger>(_ => Init(Sender));
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
}

private void Init(IActorRef sender)
{
sender.Tell(new LoggerInitialized());
}

private void OnLog(LogLevel level, string message)
{
Log<NeoSystem>(level, message);
}
}

/// <summary>
/// Load configuration with different Environment Variable
/// </summary>
Expand Down