diff --git a/Moonlight/Features/Servers/UI/Components/AdminNodeViewNavigation.razor b/Moonlight/Features/Servers/UI/Components/AdminNodeViewNavigation.razor index 47535f5..c51d3ec 100644 --- a/Moonlight/Features/Servers/UI/Components/AdminNodeViewNavigation.razor +++ b/Moonlight/Features/Servers/UI/Components/AdminNodeViewNavigation.razor @@ -9,6 +9,9 @@ + diff --git a/Moonlight/Features/Servers/UI/NodeComponents/NodeLogs.razor b/Moonlight/Features/Servers/UI/NodeComponents/NodeLogs.razor new file mode 100644 index 0000000..2808d3a --- /dev/null +++ b/Moonlight/Features/Servers/UI/NodeComponents/NodeLogs.razor @@ -0,0 +1,79 @@ +@using MoonCore.Helpers +@using Moonlight.Features.Servers.Entities +@using MoonCore.Services +@using MoonCoreUI.Services +@using Moonlight.Core.Configuration +@using Moonlight.Features.Servers.Services + +@inject ConfigService ConfigService +@inject NodeService NodeService +@inject ToastService ToastService + +
+
+
Latest logs of @Node.Name
+
+
+ + + Refresh + +
+
+
+
+ + +
+ @foreach (var line in Lines) + { + @line +
+ } +
+
+ +@code +{ + [Parameter] public ServerNode Node { get; set; } + + private string[] Lines; + private int LinesToFetch = 25; + + private async Task Load(LazyLoader lazyLoader) + { + await lazyLoader.SetText("Fetching current logs"); + await Refresh(); + } + + private async Task Refresh() + { + // Prevent too small and too big values + if (LinesToFetch < 0) + LinesToFetch = 50; + + if (LinesToFetch > 500) + LinesToFetch = 50; + + try + { + // Fetch and parse log + var logs = await NodeService.GetLogs(Node); + var logLines = logs.Split("\n"); + + // Save required logs + Lines = logLines.TakeLast(LinesToFetch).ToArray(); + + await ToastService.Success("Refreshed logs successfully"); + } + catch (Exception e) + { + Logger.Warn($"An error occured while fetching logs from node '{Node.Name}'"); + Logger.Warn(e); + + await ToastService.Danger("An error occured while fetching logs. Please try again later"); + } + + await InvokeAsync(StateHasChanged); + } +} \ No newline at end of file diff --git a/Moonlight/Features/Servers/UI/Views/Admin/Nodes/View.razor b/Moonlight/Features/Servers/UI/Views/Admin/Nodes/View.razor index 39fbab6..023e31e 100644 --- a/Moonlight/Features/Servers/UI/Views/Admin/Nodes/View.razor +++ b/Moonlight/Features/Servers/UI/Views/Admin/Nodes/View.razor @@ -29,6 +29,9 @@ + + + } @@ -65,6 +68,9 @@ case "/setup": return 2; + + case "/logs": + return 3; default: return 0;