Skip to content

Commit

Permalink
Cleanup of logging (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
helto4real committed Dec 25, 2020
1 parent 747c7fa commit 29a31ea
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/Daemon/NetDaemon.Daemon/Daemon/CodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public IEnumerable<INetDaemonAppBase> InstanceDaemonApps()
}
catch (Exception e)
{
_logger.LogError(e, "Error instance the app from the file {file}", file);
_logger.LogTrace(e, "Error instance the app from the file {file}", file);
_logger.LogError("Error instance the app from the file {file}, use trace flag for details", file);
throw new ApplicationException($"Error instance the app from the file {file}", e);
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/Daemon/NetDaemon.Daemon/Daemon/NetDaemonHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public class NetDaemonHost : INetDaemonHost, IAsyncDisposable
private CancellationTokenSource? _cancelTokenSource;
private IDictionary<string, object> _dataCache = new Dictionary<string, object>();

private bool _stopped;

/// <summary>
/// Constructor
Expand All @@ -123,7 +122,7 @@ public class NetDaemonHost : INetDaemonHost, IAsyncDisposable
_hassClient = hassClient ?? throw new ArgumentNullException("HassClient can't be null!");
_scheduler = new Scheduler(loggerFactory: loggerFactory);
_repository = repository;
Logger.LogInformation("Instance NetDaemonHost");
Logger.LogTrace("Instance NetDaemonHost");
}

public bool Connected { get; private set; }
Expand Down Expand Up @@ -449,7 +448,6 @@ public async Task Run(string host, short port, bool ssl, string token, Cancellat
await _hassClient.SubscribeToEvents().ConfigureAwait(false);

Connected = true;
_stopped = false;

Logger.LogInformation(
hassioToken != null
Expand Down Expand Up @@ -611,7 +609,6 @@ public async Task Stop()

InternalState.Clear();

_stopped = true;

Connected = false;
await _hassClient.CloseAsync().ConfigureAwait(false);
Expand Down
4 changes: 2 additions & 2 deletions src/DaemonRunner/DaemonRunner/Service/API/WsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public async Task Invoke(HttpContext context)
}
catch (Exception e)
{
_logger.LogTrace(e, "Websocket problem found");
_logger.LogTrace(e, "Unhandled error in websocket communication");
}

_sockets.TryRemove(socketId, out _);
Expand All @@ -196,7 +196,7 @@ public async Task Invoke(HttpContext context)

public async Task BroadCast(string message, CancellationToken ct = default(CancellationToken))
{
_logger.LogDebug("Broadcasting to {count} clients", _sockets.Count);
_logger.LogTrace("Broadcasting to {count} clients", _sockets.Count);
foreach (var socket in _sockets)
{
if (socket.Value.State != WebSocketState.Open)
Expand Down
31 changes: 16 additions & 15 deletions src/DaemonRunner/DaemonRunner/Service/RunnerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,32 @@ IDaemonAppCompiler daemonAppCompiler

public override async Task StopAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Stopping NetDaemon...");
_logger.LogInformation("Stopping NetDaemon service...");
await base.StopAsync(cancellationToken).ConfigureAwait(false);
}

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
try
{
_logger.LogInformation($"Starting NeDaemon service (version {Version})...");

if (_netDaemonSettings == null)
{
_logger.LogError("No config specified, file or environment variables! Exiting...");
_logger.LogError("No configuration specified, in appsettings or environment variables! Exiting...");
return;
}

_sourcePath = _netDaemonSettings.GetAppSourceDirectory();

// EnsureApplicationDirectoryExists(_netDaemonSettings);


_logger.LogDebug("Finding apps in {folder}...", _sourcePath);
_logger.LogTrace("Finding apps in {folder}...", _sourcePath);

// Automatically create source directories
if (_sourcePath is string && !Directory.Exists(_sourcePath))
throw new FileNotFoundException("Source path {path} does not exist", _sourcePath);


{
_logger.LogError("Path to app source does not exist {path}, exiting...", _sourcePath);
return;
}

_loadedDaemonApps = null;

Expand All @@ -101,7 +101,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
_logger.LogError(e, "NetDaemon had unhandled exception, closing...");
}

_logger.LogInformation("NetDaemon exited!");
_logger.LogInformation("NetDaemon service exited!");
}

private async Task Run(NetDaemonHost daemonHost, CancellationToken stoppingToken)
Expand All @@ -115,7 +115,7 @@ private async Task Run(NetDaemonHost daemonHost, CancellationToken stoppingToken
// This is due to re-connect, it must be a re-connect
// so delay before retry connect again
await Task.Delay(ReconnectInterval, stoppingToken).ConfigureAwait(false); // Wait x seconds
_logger.LogInformation($"Restarting NeDaemon (version {Version})...");
_logger.LogInformation($"Restarting NeDaemon service (version {Version})...");
}

var daemonHostTask = daemonHost.Run(
Expand Down Expand Up @@ -146,7 +146,7 @@ private async Task Run(NetDaemonHost daemonHost, CancellationToken stoppingToken

if (_loadedDaemonApps is null || !_loadedDaemonApps.Any())
{
_logger.LogError("No apps found, exiting...");
_logger.LogError("No NetDaemon apps could be found, exiting...");
return;
}

Expand All @@ -159,7 +159,7 @@ private async Task Run(NetDaemonHost daemonHost, CancellationToken stoppingToken
}
catch (TaskCanceledException)
{
_logger.LogInformation("Canceling NetDaemon service...");
_logger.LogTrace("Canceling NetDaemon service...");
}
catch (Exception e)
{
Expand All @@ -181,7 +181,8 @@ private async Task Run(NetDaemonHost daemonHost, CancellationToken stoppingToken
}
catch (Exception e)
{
_logger.LogError(e, "MAJOR ERROR!");
_logger.LogError("Error in NetDaemon service!, set trace log level to see details.");
_logger.LogTrace(e, "Error in NetDaemon service!");
}
finally
{
Expand Down Expand Up @@ -209,7 +210,7 @@ private async Task GenerateEntities(NetDaemonHost daemonHost, string sourceFolde
if (_entitiesGenerated)
return;

_logger.LogDebug("Generating entities ..");
_logger.LogTrace("Generating entities from Home Assistant instance ..");

_entitiesGenerated = true;
var codeGen = new CodeGenerator();
Expand Down

0 comments on commit 29a31ea

Please sign in to comment.