mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-08-24 20:52:11 +00:00
Refactored log viewer component and extracted LogFileKind enum
This commit is contained in:
parent
51fdfc046c
commit
8779710a70
@ -1,5 +1,4 @@
|
|||||||
@attribute [Route(Routes.ASSISTANT_LOG_VIEWER)]
|
@attribute [Route(Routes.ASSISTANT_LOG_VIEWER)]
|
||||||
@using AIStudio.Tools.Services
|
|
||||||
@inherits MSGComponentBase
|
@inherits MSGComponentBase
|
||||||
|
|
||||||
<div class="inner-scrolling-context">
|
<div class="inner-scrolling-context">
|
||||||
@ -99,7 +98,7 @@
|
|||||||
<div class="log-viewer-lines" role="textbox" aria-readonly="true">
|
<div class="log-viewer-lines" role="textbox" aria-readonly="true">
|
||||||
@foreach (var line in this.displayLines)
|
@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-number">@line.Number</span>
|
||||||
<span class="log-viewer-line-text">@((MarkupString)this.RenderLine(line))</span>
|
<span class="log-viewer-line-text">@((MarkupString)this.RenderLine(line))</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -7,6 +7,7 @@ using AIStudio.Tools.Rust;
|
|||||||
using AIStudio.Tools.Services;
|
using AIStudio.Tools.Services;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
// ReSharper disable NotAccessedPositionalProperty.Local
|
||||||
|
|
||||||
namespace AIStudio.Assistants.LogViewer;
|
namespace AIStudio.Assistants.LogViewer;
|
||||||
|
|
||||||
@ -26,9 +27,9 @@ public partial class AssistantLogViewer : MSGComponentBase
|
|||||||
["TRACE"] = 7,
|
["TRACE"] = 7,
|
||||||
};
|
};
|
||||||
|
|
||||||
private const int DEFAULT_MAX_LINES = 5000;
|
private const int DEFAULT_MAX_LINES = 5_000;
|
||||||
protected const int MIN_MAX_LINES = 100;
|
private const int MIN_MAX_LINES = 100;
|
||||||
protected const int MAX_MAX_LINES = 100000;
|
private const int MAX_MAX_LINES = 100_000;
|
||||||
private const string OTHER_OPTION_VALUE = "__OTHER__";
|
private const string OTHER_OPTION_VALUE = "__OTHER__";
|
||||||
|
|
||||||
[Inject]
|
[Inject]
|
||||||
@ -43,6 +44,10 @@ public partial class AssistantLogViewer : MSGComponentBase
|
|||||||
[Inject]
|
[Inject]
|
||||||
private ILogger<AssistantLogViewer> Logger { get; init; } = null!;
|
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 GetLogPathsResponse logPaths;
|
||||||
private LogFileKind selectedLogFile = LogFileKind.APP;
|
private LogFileKind selectedLogFile = LogFileKind.APP;
|
||||||
private List<LogLine> loadedLines = [];
|
private List<LogLine> loadedLines = [];
|
||||||
@ -50,9 +55,7 @@ public partial class AssistantLogViewer : MSGComponentBase
|
|||||||
private List<string> logLevelOptions = [OTHER_OPTION_VALUE];
|
private List<string> logLevelOptions = [OTHER_OPTION_VALUE];
|
||||||
private List<string> loggerOptions = [OTHER_OPTION_VALUE];
|
private List<string> loggerOptions = [OTHER_OPTION_VALUE];
|
||||||
private List<string> sourceDetailOptions = [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 string[] activeSearchTerms = [];
|
||||||
private CancellationTokenSource? autoRefreshCancellationTokenSource;
|
private CancellationTokenSource? autoRefreshCancellationTokenSource;
|
||||||
private string filterText = string.Empty;
|
private string filterText = string.Empty;
|
||||||
@ -141,13 +144,13 @@ public partial class AssistantLogViewer : MSGComponentBase
|
|||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
|
|
||||||
if (!this.SettingsManager.IsAssistantVisible(Tools.Components.LOG_VIEWER_ASSISTANT, assistantName: T("Log Viewer")))
|
if (!this.SettingsManager.IsAssistantVisible(Tools.Components.LOG_VIEWER_ASSISTANT, assistantName: T("Log Viewer")))
|
||||||
{
|
{
|
||||||
this.NavigationManager.NavigateTo(Routes.ASSISTANTS);
|
this.NavigationManager.NavigateTo(Routes.ASSISTANTS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logPaths = await this.RustService.GetLogPaths();
|
||||||
await this.RefreshLogAsync();
|
await this.RefreshLogAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +192,6 @@ public partial class AssistantLogViewer : MSGComponentBase
|
|||||||
private async Task AutoRefreshChanged(bool value)
|
private async Task AutoRefreshChanged(bool value)
|
||||||
{
|
{
|
||||||
this.autoRefresh = value;
|
this.autoRefresh = value;
|
||||||
|
|
||||||
if (this.autoRefresh)
|
if (this.autoRefresh)
|
||||||
this.StartAutoRefresh();
|
this.StartAutoRefresh();
|
||||||
else
|
else
|
||||||
@ -210,21 +212,6 @@ public partial class AssistantLogViewer : MSGComponentBase
|
|||||||
|
|
||||||
private async Task OpenCurrentLogInFileManager()
|
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;
|
var path = this.CurrentLogPath;
|
||||||
if (string.IsNullOrWhiteSpace(path))
|
if (string.IsNullOrWhiteSpace(path))
|
||||||
{
|
{
|
||||||
@ -290,9 +277,7 @@ public partial class AssistantLogViewer : MSGComponentBase
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.logPaths = await this.RustService.GetLogPaths();
|
|
||||||
var path = this.CurrentLogPath;
|
var path = this.CurrentLogPath;
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(path))
|
if (string.IsNullOrWhiteSpace(path))
|
||||||
{
|
{
|
||||||
this.loadedLines = [];
|
this.loadedLines = [];
|
||||||
@ -450,7 +435,7 @@ public partial class AssistantLogViewer : MSGComponentBase
|
|||||||
return parts.Count == 0 ? string.Empty : string.Join(" ", parts);
|
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;
|
var level = line.Segments.Level ?? string.Empty;
|
||||||
|
|
||||||
@ -621,7 +606,7 @@ public partial class AssistantLogViewer : MSGComponentBase
|
|||||||
|
|
||||||
private static bool IsSourceDetails(string content)
|
private static bool IsSourceDetails(string content)
|
||||||
{
|
{
|
||||||
return content.Contains("=", StringComparison.Ordinal);
|
return content.Contains('=', StringComparison.Ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int SkipWhiteSpace(string text, int start)
|
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 LogSnapshot(List<LogLine> Lines, int TotalLineCount, int SkippedLineCount);
|
||||||
|
|
||||||
private readonly record struct HighlightRange(int Start, int Length);
|
private readonly record struct HighlightRange(int Start, int Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum LogFileKind
|
|
||||||
{
|
|
||||||
APP,
|
|
||||||
STARTUP,
|
|
||||||
}
|
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
namespace AIStudio.Assistants.LogViewer;
|
||||||
|
|
||||||
|
public enum LogFileKind
|
||||||
|
{
|
||||||
|
APP,
|
||||||
|
STARTUP,
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user