Logging Enhancements (#285)

* If the user is on Debug, allow logging DB params to the logger. Implemented the ability to change logger from UI and to keep the DB settings of LogLevel and Port in sync with appsettings.

* Exclude a lot more clutter from hitting Sentry

* Removed github action

* Small cleanup
This commit is contained in:
Joseph Milazzo 2021-06-07 17:52:11 -05:00 committed by GitHub
parent 6f124b6f8a
commit 7dae1da92f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 81 additions and 16 deletions

View file

@ -7,7 +7,7 @@ namespace Kavita.Common
{
public static class Configuration
{
#region JWT Token
public static bool CheckIfJwtTokenSet(string filePath)
{
try {
@ -29,8 +29,6 @@ namespace Kavita.Common
return false;
}
public static bool UpdateJwtToken(string filePath, string token)
{
try
@ -44,7 +42,8 @@ namespace Kavita.Common
return false;
}
}
#endregion
#region Port
public static bool UpdatePort(string filePath, int port)
{
if (new OsInfo(Array.Empty<IOsVersionAdapter>()).IsDocker)
@ -64,7 +63,6 @@ namespace Kavita.Common
return false;
}
}
public static int GetPort(string filePath)
{
const int defaultPort = 5000;
@ -89,5 +87,48 @@ namespace Kavita.Common
return defaultPort;
}
#endregion
#region LogLevel
public static bool UpdateLogLevel(string filePath, string logLevel)
{
try
{
var currentLevel = GetLogLevel(filePath);
var json = File.ReadAllText(filePath).Replace($"\"Default\": \"{currentLevel}\"", $"\"Default\": \"{logLevel}\"");
File.WriteAllText(filePath, json);
return true;
}
catch (Exception)
{
return false;
}
}
public static string GetLogLevel(string filePath)
{
try {
var json = File.ReadAllText(filePath);
var jsonObj = JsonSerializer.Deserialize<dynamic>(json);
if (jsonObj.TryGetProperty("Logging", out JsonElement tokenElement))
{
foreach (var property in tokenElement.EnumerateObject())
{
if (!property.Name.Equals("LogLevel")) continue;
foreach (var logProperty in property.Value.EnumerateObject())
{
if (logProperty.Name.Equals("Default"))
{
return logProperty.Value.GetString();
}
}
}
}
}
catch (Exception ex) {
Console.WriteLine("Error writing app settings: " + ex.Message);
}
return "Information";
}
#endregion
}
}