Improved logging

This commit is contained in:
2025-06-11 13:23:51 +02:00
parent e6211a185b
commit a3d1a4679c
5 changed files with 35 additions and 16 deletions

View File

@@ -4,7 +4,7 @@ public interface IScriptable
{
ScriptToolSet ToolSet { get; set; }
ScriptUpdateInfo UpdateInfo { get; set; }
ILogger Logger { get; set; }
ILogger _logger { get; set; }
void Init();
void Update(ICallbackInfos callbackInfos);
bool IsScript(string filePath);

View File

@@ -11,10 +11,10 @@ public class PythonScriptable : IScriptable
public dynamic sys;
public string source;
public ScriptUpdateInfo UpdateInfo { get; set; }
public ILogger Logger { get; set; }
public ILogger _logger { get; set; }
public PythonScriptable(ScriptToolSet toolSet, ILogger logger)
{
Logger = logger;
_logger = logger;
Runtime.PythonDLL = @"libpython3.12.so";
if (!PythonEngine.IsInitialized)
{
@@ -56,11 +56,11 @@ public class PythonScriptable : IScriptable
UpdateInfo = new() { DateTime = DateTime.Now, Successful = false, Exception = ex };
if (retryCounter < 3)
{
Logger.LogWarning("Unable to init the scriptable - retrying", [ToolSet.filePath, ex]);
_logger.LogWarning("Unable to init the scriptable - retrying", [ToolSet.filePath, ex]);
retryCounter++;
goto retry;
}
Logger.LogError("Unable to init the scriptable", [ToolSet.filePath, ex]);
_logger.LogError("Unable to init the scriptable", [ToolSet.filePath, ex]);
throw;
}
UpdateInfo = new() { DateTime = DateTime.Now, Successful = true };
@@ -85,11 +85,11 @@ public class PythonScriptable : IScriptable
UpdateInfo = new() { DateTime = DateTime.Now, Successful = false, Exception = ex };
if (retryCounter < 3)
{
Logger.LogWarning("Execution of script failed to an exception - retrying", [ToolSet.filePath, ex]);
_logger.LogWarning("Execution of script failed to an exception - retrying", [ToolSet.filePath, ex]);
retryCounter++;
goto retry;
}
Logger.LogError("Execution of script failed to an exception", [ToolSet.filePath, ex]);
_logger.LogError("Execution of script failed to an exception", [ToolSet.filePath, ex]);
throw;
}
UpdateInfo = new() { DateTime = DateTime.Now, Successful = true };

View File

@@ -82,17 +82,19 @@ public class IntervalCall : ICall
{
public System.Timers.Timer Timer;
public IScriptable Scriptable;
public IntervalCall(System.Timers.Timer timer, IScriptable scriptable)
public ILogger _logger;
public IntervalCall(System.Timers.Timer timer, IScriptable scriptable, ILogger logger)
{
Timer = timer;
Scriptable = scriptable;
_logger = logger;
}
public HealthCheckResult HealthCheck()
{
if (!Scriptable.UpdateInfo.Successful)
{
_logger.LogWarning("HealthCheck revealed: The last execution of \"{name}\" was not successful", Scriptable.ToolSet.filePath);
return HealthCheckResult.Unhealthy();
}
double timerInterval = Timer.Interval; // In ms
@@ -101,6 +103,7 @@ public class IntervalCall : ICall
double millisecondsSinceLastExecution = now.Subtract(lastRunDateTime).TotalMilliseconds;
if (millisecondsSinceLastExecution >= 2 * timerInterval)
{
_logger.LogWarning("HealthCheck revealed: Since the last execution of \"{name}\" more than twice the interval has passed", Scriptable.ToolSet.filePath);
return HealthCheckResult.Unhealthy();
}
return HealthCheckResult.Healthy();