Skip to content

Commit

Permalink
Integrate new loggers
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-petko authored and GitHub Enterprise committed Jul 1, 2022
1 parent 9048743 commit bc9db9e
Show file tree
Hide file tree
Showing 52 changed files with 461 additions and 387 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void DoCompletionTask(SuccessFailurePort itemHandlerResult, Action compl
var choice = Arbiter.Choice(
itemHandlerResult,
(success) => completionTask(),
SystemLogger.Singleton.Error
Logger.Singleton.Error
);
Arbiter.Activate(_dispatcherQueue, choice);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void Choice<T0, T1>(PortSet<T0, T1> resultPortSet, Action<T0> handler0, A
}
catch (Exception ex)
{
SystemLogger.Singleton.Error(ex);
Logger.Singleton.Error(ex);
}
},
(result1) =>
Expand All @@ -188,7 +188,7 @@ public void Choice<T0, T1>(PortSet<T0, T1> resultPortSet, Action<T0> handler0, A
}
catch (Exception ex)
{
SystemLogger.Singleton.Error(ex);
Logger.Singleton.Error(ex);
}
}
);
Expand All @@ -206,7 +206,7 @@ public void Choice<T>(PortSet<T, Exception> resultPortSet, Action<T> successHand
Choice(
resultPortSet,
successHandler,
SystemLogger.Singleton.Error
Logger.Singleton.Error
);
}

Expand Down Expand Up @@ -298,7 +298,7 @@ public void Receive<T>(bool persist, Port<T> result, Action<T> handler)
}
catch (Exception ex)
{
SystemLogger.Singleton.Error(ex);
Logger.Singleton.Error(ex);
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private void ExecuteWorkItem(WaitQueueItem item)
try { ExecutionContext.Run(item.Context, item.Callback.Invoke, item.State); }
catch (ThreadAbortException) { }
catch (ThreadInterruptedException) { }
catch (Exception ex) { SystemLogger.Singleton.Error(ex); }
catch (Exception ex) { Logger.Singleton.Error(ex); }
}
private void MonitorPerformance(string instanceName)
{
Expand Down Expand Up @@ -169,7 +169,7 @@ private void MonitorPerformance(string instanceName)
#endif
}
catch (ThreadAbortException) { }
catch (Exception ex) { SystemLogger.Singleton.Error(ex); }
catch (Exception ex) { Logger.Singleton.Error(ex); }
}

/// <inheritdoc/>
Expand Down
4 changes: 2 additions & 2 deletions Assemblies/MFDLabs.Concurrency/Implementation/RefreshAhead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void Refresh(Func<T> refreshDelegate)
}
catch (Exception ex)
{
SystemLogger.Singleton.Error(ex);
Logger.Singleton.Error(ex);
}
}
private void Refresh(Action<PortSet<T, Exception>> refreshDelegate)
Expand All @@ -108,7 +108,7 @@ private void Refresh(Action<PortSet<T, Exception>> refreshDelegate)
}
catch (Exception ex)
{
SystemLogger.Singleton.Error(ex);
Logger.Singleton.Error(ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public DispatcherMonitor(Dispatcher dispatcher)

private void dispatcher_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
SystemLogger.Singleton.Error(new ApplicationException($"{_dispatcher.Name} had an unhandled exception", e.ExceptionObject as Exception));
Logger.Singleton.Error(new ApplicationException($"{_dispatcher.Name} had an unhandled exception", e.ExceptionObject as Exception));
}

private static void Monitor()
Expand All @@ -54,7 +54,7 @@ private static void Monitor()
}
catch (Exception ex)
{
SystemLogger.Singleton.Error(ex);
Logger.Singleton.Error(ex);
}

if (sleep != TimeSpan.Zero)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public static void OverrideDefaultConfigurationLogging(Action<string, object[]>
internal static void Info(string format, params object[] args) => Log(_overrideOnInformation, format, args);
private static void Log(Action<string, object[]> overrideLogger, string format, params object[] args) => overrideLogger?.Invoke(format, args);

private static Action<string, object[]> _overrideOnError = (f, a) => SystemLogger.Singleton.Error(f, a);
private static Action<string, object[]> _overrideOnWarning = (f, a) => SystemLogger.Singleton.Warning(f, a);
private static Action<string, object[]> _overrideOnInformation = (f, a) => SystemLogger.Singleton.Info(f, a);
private static Action<string, object[]> _overrideOnError = (f, a) => Logger.Singleton.Error(f, a);
private static Action<string, object[]> _overrideOnWarning = (f, a) => Logger.Singleton.Warning(f, a);
private static Action<string, object[]> _overrideOnInformation = (f, a) => Logger.Singleton.Info(f, a);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void RefreshToken(object s)


_vaultClientRefreshTimer.Change(-1, -1);
SystemLogger.Singleton.Info("Renewing vault client's token, '{0}...'", _tokenStr);
Logger.Singleton.Info("Renewing vault client's token, '{0}...'", _tokenStr);
_token.RenewSelfAsync().Wait();
_vaultClientRefreshTimer.Change(TimeSpan.FromHours(0.75), TimeSpan.FromHours(0.75));
}
Expand All @@ -94,9 +94,9 @@ private static IDictionary<string, object> FetchWithRetries(Func<IDictionary<str
catch (Exception ex)
{
#if DEBUG || DEBUG_LOGGING_IN_PROD
SystemLogger.Singleton.Error(ex);
Logger.Singleton.Error(ex);
#else
SystemLogger.Singleton.Warning(ex.Message);
Logger.Singleton.Warning(ex.Message);
#endif
Thread.Sleep(i * 100);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,22 @@ public static T GetSetting<T>(
}
catch (Exception ex)
{
SystemLogger.Singleton.Warning(ex.Message);
Logger.Singleton.Warning(ex.Message);

switch (ex)
{
case ArgumentNullException or ArgumentException:
SystemLogger.Singleton.Warning("There was an argument exception with your setting value " +
Logger.Singleton.Warning("There was an argument exception with your setting value " +
$"when trying to cast it to '{type.FullName}', {ex.Message}.");
return default;
case InvalidCastException:
case FormatException:
case OverflowException:
SystemLogger.Singleton.Warning("The typeof your setting value could not be casted to the " +
Logger.Singleton.Warning("The typeof your setting value could not be casted to the " +
$"type of the real setting value, which is '{type.FullName}', please try again.");
return default;
default:
SystemLogger.Singleton.Warning($"An unknown exception occurred when trying to update the setting '{settingName}'.");
Logger.Singleton.Warning($"An unknown exception occurred when trying to update the setting '{settingName}'.");

return default;
}
Expand Down
18 changes: 9 additions & 9 deletions Assemblies/MFDLabs.Grid.Arbiter/Helper/GridDeployer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private static string ConstructHealthCheckUserAgent(string url, string healthyTe

private static string GetGridServerLaunchPath()
{
SystemLogger.Singleton.Info("Trying to get the grid server's path...");
Logger.Singleton.Info("Trying to get the grid server's path...");

#if NETFRAMEWORK
var gridServicePath = Registry.GetValue(
Expand All @@ -37,7 +37,7 @@ private static string GetGridServerLaunchPath()

if (gridServicePath == null)
{
SystemLogger.Singleton.Error("The grid server is not installed on this machine.");
Logger.Singleton.Error("The grid server is not installed on this machine.");
throw new InvalidOperationException(CouldNotFindGridServer);
}

Expand Down Expand Up @@ -180,11 +180,11 @@ private static void CheckWorkspace()
if (global::MFDLabs.Grid.Properties.Settings.Default.WebServerWorkspacePath.IsNullOrEmpty())
throw new InvalidOperationException("Cannot open web server if the workspace is not set!");

SystemLogger.Singleton.Info("Checking the existance of the web server at '{0}'", global::MFDLabs.Grid.Properties.Settings.Default.WebServerWorkspacePath);
Logger.Singleton.Info("Checking the existance of the web server at '{0}'", global::MFDLabs.Grid.Properties.Settings.Default.WebServerWorkspacePath);

if (!Directory.Exists(global::MFDLabs.Grid.Properties.Settings.Default.WebServerWorkspacePath))
{
SystemLogger.Singleton.Error("Unable to launch the web server because it could not be found at the path: '{0}'", global::MFDLabs.Grid.Properties.Settings.Default.WebServerWorkspacePath);
Logger.Singleton.Error("Unable to launch the web server because it could not be found at the path: '{0}'", global::MFDLabs.Grid.Properties.Settings.Default.WebServerWorkspacePath);
throw new InvalidOperationException(CouldNotFindWebServer);
}
}
Expand All @@ -199,7 +199,7 @@ public static int LaunchGridServer(string hostName = "localhost", int port = 536
{
if (!IsServiceAvailableTcp(hostName, port, 0, 150))
{
SystemLogger.Singleton.Info("Grid server was not running on http://{0}:{1}, try to launch it.", hostName, port);
Logger.Singleton.Info("Grid server was not running on http://{0}:{1}, try to launch it.", hostName, port);

var path = GetGridServerLaunchPath();

Expand Down Expand Up @@ -241,13 +241,13 @@ public static void LaunchWebServer(int maxAttempts = 15)
return;
}

SystemLogger.Singleton.Info("Trying to launch web server...");
Logger.Singleton.Info("Trying to launch web server...");

CheckWorkspace();

for (int attempt = 0; attempt < maxAttempts; ++attempt)
{
SystemLogger.Singleton.Info("Trying to contact web server at attempt No. {0}", attempt);
Logger.Singleton.Info("Trying to contact web server at attempt No. {0}", attempt);

if (WebServerIsAvailable(out aliveButBadCheck))
{
Expand All @@ -273,13 +273,13 @@ public static WebServerDeploymentStatus LaunchWebServerSafe(int maxAttempts = 15
return WebServerDeploymentStatus.Success;
}

SystemLogger.Singleton.Info("Trying to launch web server...");
Logger.Singleton.Info("Trying to launch web server...");

CheckWorkspace();

for (int attempt = 0; attempt < maxAttempts; ++attempt)
{
SystemLogger.Singleton.Info("Trying to contact web server at attempt No. {0}", attempt);
Logger.Singleton.Info("Trying to contact web server at attempt No. {0}", attempt);

if (WebServerIsAvailable(out aliveButBadCheck))
{
Expand Down
38 changes: 19 additions & 19 deletions Assemblies/MFDLabs.Grid.Arbiter/Helper/GridProcessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ private static (TimeSpan elapsed, int procId) OpenServer(bool onlyWebServer = fa
{
var sw = Stopwatch.StartNew();
if (onlyWebServer)
SystemLogger.Singleton.Log("Try open Web Server");
Logger.Singleton.Log("Try open Web Server");
switch (onlyGridServer)
{
case true:
SystemLogger.Singleton.Log("Try open Grid Server");
Logger.Singleton.Log("Try open Grid Server");
break;
case false when !onlyWebServer:
SystemLogger.Singleton.Log("Try open Grid and Web Server");
Logger.Singleton.Log("Try open Grid and Web Server");
break;
}

Expand All @@ -42,14 +42,14 @@ private static (TimeSpan elapsed, int procId) OpenServer(bool onlyWebServer = fa
if (onlyGridServer) procId = GridDeployer.LaunchGridServer("localhost", gridServerPort != 0 ? gridServerPort : 53640);
if (onlyWebServer) GridDeployer.LaunchWebServer(15);

SystemLogger.Singleton.Info(
Logger.Singleton.Info(
"Successfully opened '{0}' Server via Memory Roblox Grid Server Deployer",
onlyWebServer ? "Web" : onlyGridServer ? "Grid" : "Web and Grid"
);
}
finally
{
SystemLogger.Singleton.Debug(
Logger.Singleton.Debug(
"Took {0}s to open Grid Server via Memory Roblox Grid Server Deployer",
sw.Elapsed.TotalSeconds.ToString("f7")
);
Expand Down Expand Up @@ -153,7 +153,7 @@ public static bool KillProcessByPidSafe(int pid)
{
if (!ProcessHelper.GetProcessById(pid, out var pr))
{
SystemLogger.Singleton.Warning("The process '{0}' is not running, ignoring...", pid);
Logger.Singleton.Warning("The process '{0}' is not running, ignoring...", pid);
return false;
}

Expand All @@ -163,21 +163,21 @@ public static bool KillProcessByPidSafe(int pid)
#endif
)
{
SystemLogger.Singleton.Warning("The process '{0}' is running on a higher context than the current process, ignoring...", pid);
Logger.Singleton.Warning("The process '{0}' is running on a higher context than the current process, ignoring...", pid);
return false;
}

KillProcessByPid(pid);

SystemLogger.Singleton.Info("Successfully closed process '{0}'.", pid);
Logger.Singleton.Info("Successfully closed process '{0}'.", pid);
return true;
}

private static void KillAllProcessByNameSafe(string name)
{
if (!ProcessHelper.GetProcessByName(name.ToLower().Replace(".exe", ""), out var pr))
{
SystemLogger.Singleton.Warning("The process '{0}' is not running, ignoring...", name);
Logger.Singleton.Warning("The process '{0}' is not running, ignoring...", name);
return;
}

Expand All @@ -188,25 +188,25 @@ private static void KillAllProcessByNameSafe(string name)

)
{
SystemLogger.Singleton.Warning("The process '{0}' is running on a higher context than the current process, ignoring...", name);
Logger.Singleton.Warning("The process '{0}' is running on a higher context than the current process, ignoring...", name);
return;
}

KillAllProcessByName(name);

SystemLogger.Singleton.Info("Successfully closed process '{0}'.", name);
Logger.Singleton.Info("Successfully closed process '{0}'.", name);
}

/// <summary>
/// "Safe" because it checks if the process exists first.
/// </summary>
public static bool KillServerSafe()
{
SystemLogger.Singleton.Log("Trying to close Backend server.");
Logger.Singleton.Log("Trying to close Backend server.");

if (!ProcessHelper.GetProcessByWindowTitle(GlobalServerJobSignature, out var server) && !ProcessHelper.GetProcessByWindowTitle(GlobalQuickServerJobSignature, out server))
{
SystemLogger.Singleton.Warning("Backend server is not running, ignoring...");
Logger.Singleton.Warning("Backend server is not running, ignoring...");
return false;
}

Expand All @@ -217,13 +217,13 @@ public static bool KillServerSafe()
)
{
// This is quite useless I think
SystemLogger.Singleton.Warning("Backend server is running on a higher context than the current process, ignoring...");
Logger.Singleton.Warning("Backend server is running on a higher context than the current process, ignoring...");
return false;
}

KillProcessByPidSafe(server.Id);

SystemLogger.Singleton.Info("Successfully closed backend Server.");
Logger.Singleton.Info("Successfully closed backend Server.");
return true;
}

Expand All @@ -232,11 +232,11 @@ public static bool KillServerSafe()
/// </summary>
public static bool KillAllGridServersSafe()
{
SystemLogger.Singleton.Log("Trying to close all open grid server instances.");
Logger.Singleton.Log("Trying to close all open grid server instances.");

if (!ProcessHelper.GetProcessByName(GridServerSignature, out var server))
{
SystemLogger.Singleton.Warning("There are no grid servers running, ignoring...");
Logger.Singleton.Warning("There are no grid servers running, ignoring...");
return false;
}

Expand All @@ -246,13 +246,13 @@ public static bool KillAllGridServersSafe()
#endif
)
{
SystemLogger.Singleton.Warning("The grid server we caught is running on a different context than us, ignoring...");
Logger.Singleton.Warning("The grid server we caught is running on a different context than us, ignoring...");
return false;
}

KillAllProcessByNameSafe(GridServerSignatureExe);

SystemLogger.Singleton.Info("Successfully closed all grid server instances.");
Logger.Singleton.Info("Successfully closed all grid server instances.");

return true;
}
Expand Down
Loading

0 comments on commit bc9db9e

Please sign in to comment.