Skip to content

Commit

Permalink
add log level overwrite and fix null error (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
glucaci authored Nov 26, 2024
1 parent a8f73fa commit 1356421
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/Core/ContainerResourceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ public ContainerResourceBuilder WithLogLevel(SourceLevels level)
/// <returns></returns>
public virtual ContainerResourceSettings Build()
{
var logLevel = Environment.GetEnvironmentVariable("SQUADRON_LOG_LEVEL");
if (Enum.TryParse(logLevel, true, out SourceLevels overriddenLogLevel))
{
_logLevel = overriddenLogLevel;
}

_options.DockerConfigResolver ??= ContainerResourceOptions.DefaultDockerConfigResolver;
_options.Logger = new Logger(_logLevel, _options);
_options.Cmd = _cmd;
Expand Down
13 changes: 11 additions & 2 deletions src/Core/DockerContainerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,18 @@ private Task Retry(Func<Task> execute)
private async Task RetryAction(Exception exception, TimeSpan t, int retryCount, Context c)
{
_settings.Logger.Warning($"Docker command failed {retryCount}. {exception.Message}");

SystemInfoResponse? systemInfo = await Client.System.GetSystemInfoAsync();
_settings.Logger.Warning($"Driver status: {string.Join(", ", systemInfo.DriverStatus)}");
_settings.Logger.Warning($"System status: {string.Join(", ", systemInfo.SystemStatus)}");

if (systemInfo is { DriverStatus: { Count: > 0 } })
{
_settings.Logger.Warning($"Driver status: {string.Join(", ", systemInfo.DriverStatus)}");
}

if (systemInfo is { SystemStatus: { Count: > 0 } })
{
_settings.Logger.Warning($"System status: {string.Join(", ", systemInfo.SystemStatus)}");
}
}

public void Dispose()
Expand Down

0 comments on commit 1356421

Please sign in to comment.