🔊 Add logs.

This commit is contained in:
Kolosov Alexandr 2024-12-06 19:30:58 +05:00
parent d01491f5cd
commit dd339130b8
8 changed files with 78 additions and 38 deletions

2
.gitignore vendored
View File

@ -342,4 +342,4 @@ healthchecksdb
*.DotSettings *.DotSettings
*.DS_Store *.DS_Store
**/*.Production.json **/*.Production.json
Logs/ **/*.log

View File

@ -42,7 +42,7 @@ public static class Extensions
public static Version ToVersion(this string textVersion) public static Version ToVersion(this string textVersion)
{ {
var version = textVersion.Replace("^", "").Replace("~", "").Split("."); var version = textVersion.Replace("^", "").Replace("v", "").Replace("~", "").Split(".");
var major = Convert.ToInt32(version[0]); var major = Convert.ToInt32(version[0]);
var minor = Convert.ToInt32(version[1]); var minor = Convert.ToInt32(version[1]);
var patch = Convert.ToInt32(version[2].Split('-')[0]); var patch = Convert.ToInt32(version[2].Split('-')[0]);

View File

@ -3,6 +3,7 @@ using TUI.Engine;
using TUI.Engine.Attributes; using TUI.Engine.Attributes;
using TUI.Engine.Components; using TUI.Engine.Components;
using TUI.Engine.Theme; using TUI.Engine.Theme;
using TUI.Logs;
using static TUI.Engine.Symbols; using static TUI.Engine.Symbols;
namespace TUI.Controls.Components; namespace TUI.Controls.Components;
@ -19,12 +20,13 @@ public class PanelComponent : ComponentBase, IComponent
private static void RenderTopLine(StringBuilder builder, Size size, string title) private static void RenderTopLine(StringBuilder builder, Size size, string title)
{ {
var halfWidth = (size.Width - title.GetWidth() - (int)Indentation.BorderWidth * 2 - var availableWidth = (size.Width - title.GetWidth() - (int)Indentation.BorderWidth * 2 -
(int)Indentation.Default * 2) / 2; (int)Indentation.Default * 2);
var halfWidth = availableWidth/ 2;
builder.Append(Angles.LeftTop); builder.Append(Angles.LeftTop);
builder.Append(Lines.Horizontal.Repeat(halfWidth)); builder.Append(Lines.Horizontal.Repeat(halfWidth));
builder.AppendFormat("{0}{1}{0}", Space.Repeat(Convert.ToInt32(Indentation.Default)), title); builder.AppendFormat("{0}{1}{0}", Space.Repeat(Convert.ToInt32(Indentation.Default)), title);
builder.Append(Lines.Horizontal.Repeat(halfWidth + halfWidth % 2)); builder.Append(Lines.Horizontal.Repeat(halfWidth + availableWidth % 2));
builder.Append(Angles.RightTop); builder.Append(Angles.RightTop);
builder.Append(LineBreak); builder.Append(LineBreak);
} }

20
src/TUI/Logs/Log.cs Normal file
View File

@ -0,0 +1,20 @@
namespace TUI.Logs;
public static class Log
{
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 Write(string icon, string message)
{
// /tld/src/TUI/file.log
var file = "file.log";
var line = string.Join('|', Now, icon, message);
File.AppendAllText(file, line + Environment.NewLine);
}
}

View File

@ -1,4 +1,5 @@
using System.Diagnostics; using System.Diagnostics;
using TUI.Logs;
namespace TUI.Pages; namespace TUI.Pages;
@ -6,7 +7,8 @@ public abstract class PageBase : IPage
{ {
public void Open() public void Open()
{ {
Debugger.Log(0, "Event", $"Open page ${GetType().UnderlyingSystemType.Name}\n"); Debugger.Log(0, "Event", $"Open page {GetType().UnderlyingSystemType.Name}\n");
Log.Trace($"Open page {GetType().UnderlyingSystemType.Name}.");
Bind(); Bind();
Initial(); Initial();
Render(); Render();

View File

@ -1,9 +1,12 @@
using TUI.Pages; using TUI.Logs;
using TUI.Pages;
Console.Clear(); Console.Clear();
Console.CursorVisible = false; Console.CursorVisible = false;
Log.Info("Run application.");
var welcomePage = WelcomePage.Instance; var welcomePage = WelcomePage.Instance;
welcomePage.Open(); welcomePage.Open();
Thread.Sleep(500); Thread.Sleep(500);
@ -21,9 +24,11 @@ do
{ {
case ConsoleKey.Q: case ConsoleKey.Q:
waitCommand = false; waitCommand = false;
Log.Trace("Run command quit.");
break; break;
case ConsoleKey.R: case ConsoleKey.R:
key = null; key = null;
Log.Trace("Run command load deps.");
currentPage.Load(); currentPage.Load();
break; break;
case ConsoleKey.D1: case ConsoleKey.D1:
@ -44,5 +49,6 @@ do
} }
} while (waitCommand); } while (waitCommand);
Log.Info("Quit application.");
Console.Clear(); Console.Clear();
Console.CursorVisible = true; Console.CursorVisible = true;

View File

@ -1,6 +1,7 @@
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Nodes; using System.Text.Json.Nodes;
using TUI.Domain; using TUI.Domain;
using TUI.Logs;
using YamlDotNet.Serialization; using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions; using YamlDotNet.Serialization.NamingConventions;
@ -70,9 +71,8 @@ public class DependencyRepository
var endpoint = GetGitlabEndpoint(project.Hub.Origin, project.Id); var endpoint = GetGitlabEndpoint(project.Hub.Origin, project.Id);
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);
Log.Debug($"Fetch dependencies for project {project.Name}.");
dependencies.AddRange(Map(packageJson?.Dependencies)); dependencies.AddRange(Map(packageJson?.Dependencies));
dependencies.AddRange(Map(packageJson?.DevDependencies)); dependencies.AddRange(Map(packageJson?.DevDependencies));
dependencies.AddRange(Map(packageJson?.Engines)); dependencies.AddRange(Map(packageJson?.Engines));

View File

@ -3,6 +3,7 @@ using TUI.Controls.Components;
using TUI.Domain; using TUI.Domain;
using TUI.Engine; using TUI.Engine;
using TUI.Engine.Theme; using TUI.Engine.Theme;
using TUI.Logs;
using TUI.Providers.Dependencies; using TUI.Providers.Dependencies;
namespace TUI.Store; namespace TUI.Store;
@ -26,6 +27,7 @@ public class DependenciesStore
} }
catch(Exception ex) catch(Exception ex)
{ {
Log.Error("Fail load actual deps for project " +project.Name + ". " + ex.Message);
Debugger.Log(0, "error", ex.Message); Debugger.Log(0, "error", 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>();
@ -33,11 +35,19 @@ public class DependenciesStore
} }
public void Bind() public void Bind()
{
try
{ {
SpeakerComponent.Instance.Shout("🤔", "Prepare javascript conventions"); SpeakerComponent.Instance.Shout("🤔", "Prepare javascript conventions");
ConventionDependencies = Repository.ReadConventions("javascript"); ConventionDependencies = Repository.ReadConventions("javascript");
SpeakerComponent.Instance.Shout("🤩", "Prepare javascript projects"); SpeakerComponent.Instance.Shout("🤩", "Prepare javascript projects");
Projects = Repository.ReadProjects("javascript"); Projects = Repository.ReadProjects("javascript");
Log.Info("Loading settings.");
}
catch (Exception ex)
{
Log.Error("Fail Loading settings. " + ex.Message);
}
} }
} }