diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-10-01 17:24:34 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2022-10-01 17:24:34 -0500 |
| commit | 65bb516bd6d9d8caa262d5e3d1369f4221ab38dd (patch) | |
| tree | 92eb88165ef26dbc91540f7ca6f761da1f8598b9 /src | |
| parent | 36b1e1d4537d817d7a02987a25e5f0cc792d5f8f (diff) | |
| download | slskd-65bb516bd6d9d8caa262d5e3d1369f4221ab38dd.tar.gz | |
use correct logger
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Program.cs | 6 | ||||
| -rw-r--r-- | src/slskd/Shares/ShareRepository.cs | 10 | ||||
| -rw-r--r-- | src/slskd/Shares/ShareScanner.cs | 6 | ||||
| -rw-r--r-- | src/slskd/Shares/ShareService.cs | 16 |
4 files changed, 26 insertions, 12 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 03870f0a..8dbf39ff 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -823,9 +823,11 @@ namespace slskd outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")) .WriteTo.Sink(new DelegatingSink(logEvent => { + string message = default; + try { - var message = logEvent.RenderMessage(); + message = logEvent.RenderMessage(); if (logEvent.Exception != null) { @@ -846,7 +848,7 @@ namespace slskd } catch (Exception ex) { - Log.Information($"Misconfigured delegating logger: {ex.Message}"); + Log.Error("Misconfigured delegating logger: {Exception}. Message: {Message}", ex.Message, message); } })) .CreateLogger(); diff --git a/src/slskd/Shares/ShareRepository.cs b/src/slskd/Shares/ShareRepository.cs index ba4b714c..b8ecd2be 100644 --- a/src/slskd/Shares/ShareRepository.cs +++ b/src/slskd/Shares/ShareRepository.cs @@ -23,6 +23,7 @@ namespace slskd.Shares using System.Linq; using Microsoft.Data.Sqlite; using Serilog; + using slskd.Transfers.Uploads; using Soulseek; /// <summary> @@ -142,6 +143,7 @@ namespace slskd.Shares } private string ConnectionString { get; } + private ILogger Log { get; } = Serilog.Log.ForContext<ShareRepository>(); /// <summary> /// Attempts to validate the database at the specified <paramref name="connectionString"/>. @@ -156,6 +158,8 @@ namespace slskd.Shares throw new ArgumentNullException(nameof(connectionString), "A connection string is required"); } + var log = Serilog.Log.ForContext<ShareRepository>(); + var schema = new Dictionary<string, string>() { { "directories", "CREATE TABLE directories (name TEXT PRIMARY KEY, timestamp INTEGER NOT NULL)" }, @@ -165,7 +169,7 @@ namespace slskd.Shares try { - Log.Debug("Validating shares database with connection string {String}", connectionString); + log.Debug("Validating shares database with connection string {String}", connectionString); using var conn = new SqliteConnection(connectionString); conn.Open(); @@ -188,7 +192,7 @@ namespace slskd.Shares } else { - Log.Debug("Shares database table {Table} is valid: {Actual}", table, actualSql); + log.Debug("Shares database table {Table} is valid: {Actual}", table, actualSql); } } @@ -204,7 +208,7 @@ namespace slskd.Shares } catch (Exception ex) { - Log.Debug(ex, $"Failed to validate shares database with connection string {connectionString}: {ex.Message}"); + log.Debug(ex, $"Failed to validate shares database with connection string {connectionString}: {ex.Message}"); return false; } } diff --git a/src/slskd/Shares/ShareScanner.cs b/src/slskd/Shares/ShareScanner.cs index 3edd84c1..369e4981 100644 --- a/src/slskd/Shares/ShareScanner.cs +++ b/src/slskd/Shares/ShareScanner.cs @@ -125,12 +125,12 @@ namespace slskd.Shares // validate the tables, and if there's an issue, drop and recreate everything. if (!ShareRepository.TryValidateDatabase(Program.ConnectionStrings.Shares)) { - Log.Warning("Shared file cache invalid; dropping and re-creating prior to scan."); + Log.Warning("Shared file cache missing or invalid. Re-creating prior to scan."); Repository.Create(discardExisting: true); - Log.Information("Share file cache ready."); + Log.Information("Shared file cache re-created and ready for scan."); } - Log.Debug("Starting shared file scan"); + Log.Information("Starting shared file scan"); var timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs index cebb15f6..4c107ed2 100644 --- a/src/slskd/Shares/ShareService.cs +++ b/src/slskd/Shares/ShareService.cs @@ -28,6 +28,7 @@ namespace slskd.Shares using System.Threading; using System.Threading.Tasks; using Serilog; + using slskd.Transfers.Uploads; using Soulseek; /// <summary> @@ -96,6 +97,7 @@ namespace slskd.Shares private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1, 1); private List<Regex> FilterRegexes { get; set; } = new List<Regex>(); private StorageMode CacheStorageMode { get; } + private ILogger Log { get; } = Serilog.Log.ForContext<ShareService>(); /// <summary> /// Returns the entire contents of the share. @@ -267,12 +269,18 @@ namespace slskd.Shares Log.Warning("Share cache couldn't be loaded from backup"); await InitializeAsync(forceRescan: true); } + else + { + Log.Debug("Share cache backup located. Attempting to restore..."); - Log.Debug("Share cache backup located. Attempting to restore..."); - - Repository.RestoreFrom(connectionString: Program.ConnectionStrings.SharesBackup); + Repository.RestoreFrom(connectionString: Program.ConnectionStrings.SharesBackup); - Log.Information("Share cache successfully restored from backup"); + Log.Information("Share cache successfully restored from backup"); + } + } + else + { + // the cache mode is disk and the existing db is valid. nothing to do. } // one of several thigns happened above before we got here: |
