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 4 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
2 changes: 1 addition & 1 deletion src/neo/Consensus/ConsensusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private void InitializeConsensus(byte viewNumber)

private void Log(string message, LogLevel level = LogLevel.Info)
{
Utility.Log(nameof(ConsensusService), level, message);
Utility.Log<ConsensusService>(level, message);
}

private void OnChangeViewReceived(ConsensusPayload payload, ChangeView message)
Expand Down
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
}
}
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}");
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}");
}
}
}
Expand Down
29 changes: 29 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));
}

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 All @@ -25,5 +49,10 @@ public static void Log(string source, LogLevel level, string message)
foreach (ILogPlugin plugin in Plugin.Loggers)
plugin.Log(source, level, message);
}

public static void Log<T>(LogLevel level, string message)
{
Log(typeof(T).Name, level, message);
}
}
}