Refactored log viewer component and extracted LogFileKind enum

This commit is contained in:
Thorsten Sommer 2026-07-15 18:59:21 +02:00
parent 51fdfc046c
commit 8779710a70
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108
3 changed files with 21 additions and 36 deletions

View File

@ -1,5 +1,4 @@
@attribute [Route(Routes.ASSISTANT_LOG_VIEWER)]
@using AIStudio.Tools.Services
@inherits MSGComponentBase
<div class="inner-scrolling-context">
@ -99,7 +98,7 @@
<div class="log-viewer-lines" role="textbox" aria-readonly="true">
@foreach (var line in this.displayLines)
{
<div class="@this.GetLineClass(line)">
<div class="@GetLineClass(line)">
<span class="log-viewer-line-number">@line.Number</span>
<span class="log-viewer-line-text">@((MarkupString)this.RenderLine(line))</span>
</div>

View File

@ -7,6 +7,7 @@ using AIStudio.Tools.Rust;
using AIStudio.Tools.Services;
using Microsoft.AspNetCore.Components;
// ReSharper disable NotAccessedPositionalProperty.Local
namespace AIStudio.Assistants.LogViewer;
@ -26,9 +27,9 @@ public partial class AssistantLogViewer : MSGComponentBase
["TRACE"] = 7,
};
private const int DEFAULT_MAX_LINES = 5000;
protected const int MIN_MAX_LINES = 100;
protected const int MAX_MAX_LINES = 100000;
private const int DEFAULT_MAX_LINES = 5_000;
private const int MIN_MAX_LINES = 100;
private const int MAX_MAX_LINES = 100_000;
private const string OTHER_OPTION_VALUE = "__OTHER__";
[Inject]
@ -43,6 +44,10 @@ public partial class AssistantLogViewer : MSGComponentBase
[Inject]
private ILogger<AssistantLogViewer> Logger { get; init; } = null!;
private readonly HashSet<string> selectedLogLevels = new(StringComparer.OrdinalIgnoreCase);
private readonly HashSet<string> selectedLoggers = new(StringComparer.OrdinalIgnoreCase);
private readonly HashSet<string> selectedSourceDetails = new(StringComparer.OrdinalIgnoreCase);
private GetLogPathsResponse logPaths;
private LogFileKind selectedLogFile = LogFileKind.APP;
private List<LogLine> loadedLines = [];
@ -50,9 +55,7 @@ public partial class AssistantLogViewer : MSGComponentBase
private List<string> logLevelOptions = [OTHER_OPTION_VALUE];
private List<string> loggerOptions = [OTHER_OPTION_VALUE];
private List<string> sourceDetailOptions = [OTHER_OPTION_VALUE];
private HashSet<string> selectedLogLevels = new(StringComparer.OrdinalIgnoreCase);
private HashSet<string> selectedLoggers = new(StringComparer.OrdinalIgnoreCase);
private HashSet<string> selectedSourceDetails = new(StringComparer.OrdinalIgnoreCase);
private string[] activeSearchTerms = [];
private CancellationTokenSource? autoRefreshCancellationTokenSource;
private string filterText = string.Empty;
@ -141,13 +144,13 @@ public partial class AssistantLogViewer : MSGComponentBase
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
if (!this.SettingsManager.IsAssistantVisible(Tools.Components.LOG_VIEWER_ASSISTANT, assistantName: T("Log Viewer")))
{
this.NavigationManager.NavigateTo(Routes.ASSISTANTS);
return;
}
this.logPaths = await this.RustService.GetLogPaths();
await this.RefreshLogAsync();
}
@ -189,7 +192,6 @@ public partial class AssistantLogViewer : MSGComponentBase
private async Task AutoRefreshChanged(bool value)
{
this.autoRefresh = value;
if (this.autoRefresh)
this.StartAutoRefresh();
else
@ -210,21 +212,6 @@ public partial class AssistantLogViewer : MSGComponentBase
private async Task OpenCurrentLogInFileManager()
{
try
{
this.logPaths = await this.RustService.GetLogPaths();
}
catch (Exception e)
{
this.Logger.LogWarning(e, "Could not refresh the log file paths before opening the file manager.");
this.Snackbar.Add(T("The log file path is not available yet."), Severity.Warning, config =>
{
config.Icon = Icons.Material.Filled.Folder;
config.IconSize = Size.Large;
});
return;
}
var path = this.CurrentLogPath;
if (string.IsNullOrWhiteSpace(path))
{
@ -290,9 +277,7 @@ public partial class AssistantLogViewer : MSGComponentBase
try
{
this.logPaths = await this.RustService.GetLogPaths();
var path = this.CurrentLogPath;
if (string.IsNullOrWhiteSpace(path))
{
this.loadedLines = [];
@ -450,7 +435,7 @@ public partial class AssistantLogViewer : MSGComponentBase
return parts.Count == 0 ? string.Empty : string.Join(" ", parts);
}
private string GetLineClass(LogLine line)
private static string GetLineClass(LogLine line)
{
var level = line.Segments.Level ?? string.Empty;
@ -621,7 +606,7 @@ public partial class AssistantLogViewer : MSGComponentBase
private static bool IsSourceDetails(string content)
{
return content.Contains("=", StringComparison.Ordinal);
return content.Contains('=', StringComparison.Ordinal);
}
private static int SkipWhiteSpace(string text, int start)
@ -779,10 +764,4 @@ public partial class AssistantLogViewer : MSGComponentBase
private readonly record struct LogSnapshot(List<LogLine> Lines, int TotalLineCount, int SkippedLineCount);
private readonly record struct HighlightRange(int Start, int Length);
}
public enum LogFileKind
{
APP,
STARTUP,
}
}

View File

@ -0,0 +1,7 @@
namespace AIStudio.Assistants.LogViewer;
public enum LogFileKind
{
APP,
STARTUP,
}