From efa70ffa5d5c756d7f233cd4a5a53b934213381b Mon Sep 17 00:00:00 2001 From: John Lambert Date: Tue, 10 Sep 2024 08:07:46 -0400 Subject: [PATCH] More updates for logging: * Ignore all the HttpClient requests to the world * Log each time a translation (or similar) is requested. --- .../EchoTranslationEngine/appsettings.json | 5 ++-- .../appsettings.Development.json | 3 +-- .../appsettings.json | 2 +- .../Serval.Machine.JobServer/appsettings.json | 2 +- .../src/Serval.ApiServer/appsettings.json | 5 ++++ .../TranslationEnginesController.cs | 23 ++++++++++++++++++- 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/Echo/src/EchoTranslationEngine/appsettings.json b/src/Echo/src/EchoTranslationEngine/appsettings.json index 10f68b8c..7f11a4ed 100644 --- a/src/Echo/src/EchoTranslationEngine/appsettings.json +++ b/src/Echo/src/EchoTranslationEngine/appsettings.json @@ -2,8 +2,9 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Warning" + "Microsoft.AspNetCore": "Warning", + "System.Net.Http.HttpClient": "Warning" } }, "AllowedHosts": "*" -} +} \ No newline at end of file diff --git a/src/Machine/src/Serval.Machine.EngineServer/appsettings.Development.json b/src/Machine/src/Serval.Machine.EngineServer/appsettings.Development.json index e7f18aeb..8e64ca4b 100644 --- a/src/Machine/src/Serval.Machine.EngineServer/appsettings.Development.json +++ b/src/Machine/src/Serval.Machine.EngineServer/appsettings.Development.json @@ -14,8 +14,7 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Warning", - "System.Net.Http.HttpClient.Default": "Warning" + "Microsoft.AspNetCore": "Warning" } } } \ No newline at end of file diff --git a/src/Machine/src/Serval.Machine.EngineServer/appsettings.json b/src/Machine/src/Serval.Machine.EngineServer/appsettings.json index 271163ff..f17d77f3 100644 --- a/src/Machine/src/Serval.Machine.EngineServer/appsettings.json +++ b/src/Machine/src/Serval.Machine.EngineServer/appsettings.json @@ -37,7 +37,7 @@ }, "Logging": { "LogLevel": { - "System.Net.Http.HttpClient.Default": "Warning" + "System.Net.Http.HttpClient": "Warning" } } } \ No newline at end of file diff --git a/src/Machine/src/Serval.Machine.JobServer/appsettings.json b/src/Machine/src/Serval.Machine.JobServer/appsettings.json index 2540e141..d1934bc0 100644 --- a/src/Machine/src/Serval.Machine.JobServer/appsettings.json +++ b/src/Machine/src/Serval.Machine.JobServer/appsettings.json @@ -38,7 +38,7 @@ }, "Logging": { "LogLevel": { - "System.Net.Http.HttpClient.Default": "Warning" + "System.Net.Http.HttpClient": "Warning" } } } \ No newline at end of file diff --git a/src/Serval/src/Serval.ApiServer/appsettings.json b/src/Serval/src/Serval.ApiServer/appsettings.json index cb35bd0f..496183ef 100644 --- a/src/Serval/src/Serval.ApiServer/appsettings.json +++ b/src/Serval/src/Serval.ApiServer/appsettings.json @@ -9,5 +9,10 @@ }, "DataFile": { "FilesDirectory": "/var/lib/serval/files" + }, + "Logging": { + "LogLevel": { + "System.Net.Http.HttpClient": "Warning" + } } } \ No newline at end of file diff --git a/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs b/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs index d11d8679..6bbcd5f3 100644 --- a/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs +++ b/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs @@ -9,7 +9,8 @@ public class TranslationEnginesController( IBuildService buildService, IPretranslationService pretranslationService, IOptionsMonitor apiOptions, - IUrlService urlService + IUrlService urlService, + ILogger logger ) : ServalControllerBase(authService) { private static readonly JsonSerializerOptions ObjectJsonSerializerOptions = @@ -20,6 +21,7 @@ IUrlService urlService private readonly IPretranslationService _pretranslationService = pretranslationService; private readonly IOptionsMonitor _apiOptions = apiOptions; private readonly IUrlService _urlService = urlService; + private readonly ILogger _logger = logger; /// /// Get all translation engines @@ -185,6 +187,7 @@ CancellationToken cancellationToken { await AuthorizeAsync(id, cancellationToken); TranslationResult result = await _engineService.TranslateAsync(id, segment, cancellationToken); + _logger.LogInformation("Translated segment for engine {EngineId}", id); return Ok(Map(result)); } @@ -222,6 +225,7 @@ CancellationToken cancellationToken { await AuthorizeAsync(id, cancellationToken); IEnumerable results = await _engineService.TranslateAsync(id, n, segment, cancellationToken); + _logger.LogInformation("Translated {n} segments for engine {EngineId}", n, id); return Ok(results.Select(Map)); } @@ -257,6 +261,7 @@ CancellationToken cancellationToken { await AuthorizeAsync(id, cancellationToken); WordGraph wordGraph = await _engineService.GetWordGraphAsync(id, segment, cancellationToken); + _logger.LogInformation("Got word graph for engine {EngineId}", id); return Ok(Map(wordGraph)); } @@ -303,6 +308,7 @@ await _engineService.TrainSegmentPairAsync( segmentPair.SentenceStart, cancellationToken ); + _logger.LogInformation("Trained segment pair for engine {EngineId}", id); return Ok(); } @@ -557,6 +563,13 @@ CancellationToken cancellationToken textId, cancellationToken ); + _logger.LogInformation( + "Returning {Count} pretranslations for engine {EngineId}, corpus {CorpusId}, and query {TextId}", + pretranslations.Count(), + id, + corpusId, + textId + ); return Ok(pretranslations.Select(Map)); } @@ -612,6 +625,13 @@ CancellationToken cancellationToken textId, cancellationToken ); + _logger.LogInformation( + "Returning {Count} pretranslations for engine {EngineId}, corpus {CorpusId}, and textId {TextId}", + pretranslations.Count(), + id, + corpusId, + textId + ); return Ok(pretranslations.Select(Map)); } @@ -684,6 +704,7 @@ CancellationToken cancellationToken ); if (usfm == "") return NoContent(); + _logger.LogInformation("Returning USFM for {TextId} in {CorpusId} of {EngineId}", textId, corpusId, id); return Content(usfm, "text/plain"); }