node: Create a locker for multiple Console.Write
Currently we can receive from plugins some outputs that can be mixed with the entered command. We should be able to send these results together.
Related to https://github.com/neo-project/neo-node/pull/905#discussion_r1392224809
We need somthing like:
public static class ConsoleHelper
{
public static readonly object Locker = new();
...
public static void Info(params string[] values)
{
lock (Locker)
{
var currentColor = new ConsoleColorSet();
for (int i = 0; i < values.Length; i++)
{
if (i % 2 == 0)
InfoColor.Apply();
else
currentColor.Apply();
Console.Write(values[i]);
}
currentColor.Apply();
Console.WriteLine();
}
}
In order to allow lock(ConsoleHelper.Lock){ ... multiple out ... }
Wouldn't it be better to do this on neo-core
namespace Neo
{
public delegate void LogEventHandler(string source, LogLevel level, object message);
public static class Utility
{
internal class Logger : ReceiveActor
{
public Logger()
{
Receive<InitializeLogger>(_ => Sender.Tell(new LoggerInitialized()));
Receive<LogEvent>(e => Log(e.LogSource, (LogLevel)e.LogLevel(), e.Message));
}
}
public static event LogEventHandler Logging;
public static Encoding StrictUTF8 { get; }
static Utility()
{
StrictUTF8 = (Encoding)Encoding.UTF8.Clone();
StrictUTF8.DecoderFallback = DecoderFallback.ExceptionFallback;
StrictUTF8.EncoderFallback = EncoderFallback.ExceptionFallback;
}
public static object ConsoleLock { get; } = new(); // Add this line
public static void Log(string source, LogLevel level, object message)
{
lock (ConsoleLock) // Add this line
Logging?.Invoke(source, level, message);
}
}
}
Because the plugin you were talking about uses, Utility.Log
I did find this in neo-cli; syncRoot its for locking so you can sync root of console.
this can be closed. has one built-in
@shargon
I did find this in neo-cli; syncRoot its for locking so you can sync root of console.
Where is syncRoot?
It is in neo-cli
https://github.com/neo-project/neo-node/blob/da786195cfb6d70236bb37611c37d7016bbc3aae/neo-cli/CLI/MainService.Logger.cs#L29
But is private, how can be used in https://github.com/neo-project/neo-node/pull/905 ?
Its a partial class
https://github.com/neo-project/neo-node/blob/da786195cfb6d70236bb37611c37d7016bbc3aae/neo-cli/CLI/MainService.cs#L41
But we also use Console outside this repo, in plugins, we should have access to it
We can make it public and do something like https://github.com/neo-project/neo/issues/2995
problem solved? with https://github.com/neo-project/neo/issues/2995#issuecomment-1844875392