From 5eda85d0069051b50fceb0d7ee6aa69feebdafcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=9A=D0=BE=D0=BB=D0=BE=D1=81=D0=BE=D0=B2?= Date: Tue, 10 Dec 2024 18:42:07 +0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8A=20Add=20log=20levels.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/TUI/Logs/Log.cs | 52 ++++++++++++++++--- .../Dependencies/DependencyRepository.cs | 1 + src/TUI/Store/DependenciesStore.cs | 18 +++++-- 3 files changed, 61 insertions(+), 10 deletions(-) diff --git a/src/TUI/Logs/Log.cs b/src/TUI/Logs/Log.cs index 2b416d0..f497ffb 100644 --- a/src/TUI/Logs/Log.cs +++ b/src/TUI/Logs/Log.cs @@ -1,14 +1,54 @@ namespace TUI.Logs; +enum Level +{ + Trace = 60, + Debug = 50, + Info = 40, + Warning = 30, + Error = 20, + Fatal = 10, +} + 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"); - public static void Trace(string message) => Write("🌚", message); - public static void Debug(string message) => Write("🦎", message); - public static void Info(string message) => Write("🦋", message); - public static void Warning(string message) => Write("🍋", message); - public static void Error(string message) => Write("🐞", message); - public static void Fatal(string message) => Write("💀", message); + public static void Trace(string message) + { + if (LogLevel < 60) return; + 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) { diff --git a/src/TUI/Providers/Dependencies/DependencyRepository.cs b/src/TUI/Providers/Dependencies/DependencyRepository.cs index 56f54c6..9503297 100644 --- a/src/TUI/Providers/Dependencies/DependencyRepository.cs +++ b/src/TUI/Providers/Dependencies/DependencyRepository.cs @@ -69,6 +69,7 @@ public class DependencyRepository if (project.Hub.Type == "gitlab") { var endpoint = GetGitlabEndpoint(project.Hub.Origin, project.Id); + Log.Trace($"Fetch endpoint {endpoint}."); using HttpClient client = new(); var json = client.GetStringAsync(endpoint).GetAwaiter().GetResult(); var packageJson = JsonSerializer.Deserialize(json); diff --git a/src/TUI/Store/DependenciesStore.cs b/src/TUI/Store/DependenciesStore.cs index 7441dbd..86ecbb1 100644 --- a/src/TUI/Store/DependenciesStore.cs +++ b/src/TUI/Store/DependenciesStore.cs @@ -25,11 +25,21 @@ public class DependenciesStore { return Repository.ReadActual(project); } - catch(Exception ex) + catch (Exception ex) { - Log.Error("Fail load actual deps for project " +project.Name + ". " + ex.Message); - Debugger.Log(0, "error", ex.Message); - SpeakerComponent.Instance.Shout(Symbols.Error.Error(), $"Fetch failed for project{project.Name}"); + if (ex.Message.Contains("404 (Not Found)")) + { + Log.Warning("Fail load actual deps for project " + project.Name + "."); + 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}"); + } + return new List(); } }