🔊 Add log levels.

This commit is contained in:
Kolosov Alexandr 2024-12-10 18:42:07 +05:00
parent 220c33ed97
commit 5eda85d006
3 changed files with 61 additions and 10 deletions

View File

@ -1,14 +1,54 @@
namespace TUI.Logs; namespace TUI.Logs;
enum Level
{
Trace = 60,
Debug = 50,
Info = 40,
Warning = 30,
Error = 20,
Fatal = 10,
}
public static class Log public static class Log
{ {
private static readonly int LogLevel = (int)Level.Info;
private static string Now => DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); private static string Now => DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
public static void Trace(string message) => Write("🌚", message); public static void Trace(string message)
public static void Debug(string message) => Write("🦎", message); {
public static void Info(string message) => Write("🦋", message); if (LogLevel < 60) return;
public static void Warning(string message) => Write("🍋", message); Write("🌚", message);
public static void Error(string message) => Write("🐞", message); }
public static void Fatal(string message) => Write("💀", message);
public static void Debug(string message)
{
if (LogLevel < 50) return;
Write("🦎", message);
}
public static void Info(string message)
{
if (LogLevel < 40) return;
Write("🦋", message);
}
public static void Warning(string message)
{
if (LogLevel < 30) return;
Write("🍋", message);
}
public static void Error(string message)
{
if (LogLevel < 20) return;
Write("🐞", message);
}
public static void Fatal(string message)
{
if (LogLevel < 10) return;
Write("💀", message);
}
public static void Write(string icon, string message) public static void Write(string icon, string message)
{ {

View File

@ -69,6 +69,7 @@ public class DependencyRepository
if (project.Hub.Type == "gitlab") if (project.Hub.Type == "gitlab")
{ {
var endpoint = GetGitlabEndpoint(project.Hub.Origin, project.Id); var endpoint = GetGitlabEndpoint(project.Hub.Origin, project.Id);
Log.Trace($"Fetch endpoint {endpoint}.");
using HttpClient client = new(); using HttpClient client = new();
var json = client.GetStringAsync(endpoint).GetAwaiter().GetResult(); var json = client.GetStringAsync(endpoint).GetAwaiter().GetResult();
var packageJson = JsonSerializer.Deserialize<PackageJson>(json); var packageJson = JsonSerializer.Deserialize<PackageJson>(json);

View File

@ -27,9 +27,19 @@ public class DependenciesStore
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Error("Fail load actual deps for project " +project.Name + ". " + ex.Message); if (ex.Message.Contains("404 (Not Found)"))
{
Log.Warning("Fail load actual deps for project " + project.Name + ".");
Debugger.Log(0, "error", ex.Message); Debugger.Log(0, "error", ex.Message);
SpeakerComponent.Instance.Shout(Symbols.Error.Warning(), $"Project {project.Name} not found.");
}
else
{
Log.Error("Fetch failed for project " + project.Name + ". " + ex.Message);
Debugger.Log(0, "warning", ex.Message);
SpeakerComponent.Instance.Shout(Symbols.Error.Error(), $"Fetch failed for project{project.Name}"); SpeakerComponent.Instance.Shout(Symbols.Error.Error(), $"Fetch failed for project{project.Name}");
}
return new List<Dependency>(); return new List<Dependency>();
} }
} }