Add client log filters and dashboard links
TaxBaik CI/CD / build-and-deploy (push) Successful in 4m52s
TaxBaik CI/CD / build-and-deploy (push) Successful in 4m52s
This commit is contained in:
@@ -18,12 +18,10 @@ public sealed class RecentClientLogEntry
|
||||
|
||||
public sealed class GetRecentLogsEndpoint : EndpointWithoutRequest<IReadOnlyList<RecentClientLogEntry>>
|
||||
{
|
||||
private readonly ILogger<GetRecentLogsEndpoint> _logger;
|
||||
private readonly IWebHostEnvironment _environment;
|
||||
|
||||
public GetRecentLogsEndpoint(ILogger<GetRecentLogsEndpoint> logger, IWebHostEnvironment environment)
|
||||
public GetRecentLogsEndpoint(IWebHostEnvironment environment)
|
||||
{
|
||||
_logger = logger;
|
||||
_environment = environment;
|
||||
}
|
||||
|
||||
@@ -35,6 +33,11 @@ public sealed class GetRecentLogsEndpoint : EndpointWithoutRequest<IReadOnlyList
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
var level = Query<string>("level");
|
||||
var source = Query<string>("source");
|
||||
var route = Query<string>("route");
|
||||
var term = Query<string>("q");
|
||||
|
||||
var logDir = Path.Combine(_environment.ContentRootPath, "logs");
|
||||
if (!Directory.Exists(logDir))
|
||||
{
|
||||
@@ -56,7 +59,9 @@ public sealed class GetRecentLogsEndpoint : EndpointWithoutRequest<IReadOnlyList
|
||||
if (!line.Contains("ClientLog ", StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
|
||||
entries.Add(Parse(line));
|
||||
var entry = Parse(line);
|
||||
if (Matches(entry, level, source, route, term))
|
||||
entries.Add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +85,36 @@ public sealed class GetRecentLogsEndpoint : EndpointWithoutRequest<IReadOnlyList
|
||||
return entry;
|
||||
}
|
||||
|
||||
private static bool Matches(RecentClientLogEntry entry, string? level, string? source, string? route, string? term)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(level) &&
|
||||
!string.Equals(entry.Level, level, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(source) &&
|
||||
!(entry.Source?.Contains(source, StringComparison.OrdinalIgnoreCase) ?? false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(route) &&
|
||||
!(entry.Route?.Contains(route, StringComparison.OrdinalIgnoreCase) ?? false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(term) &&
|
||||
!(entry.Message?.Contains(term, StringComparison.OrdinalIgnoreCase) ?? false) &&
|
||||
!(entry.Source?.Contains(term, StringComparison.OrdinalIgnoreCase) ?? false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static string? Extract(string text, string start, string end)
|
||||
{
|
||||
var index = text.IndexOf(start, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
Reference in New Issue
Block a user