From a981d98ba5d7d936fb2e9658cf5e27bfee5955e3 Mon Sep 17 00:00:00 2001 From: Evan Reichard Date: Sun, 1 Dec 2024 19:48:51 -0500 Subject: [PATCH] feat(admin): basic log filter --- api/app-admin-routes.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/api/app-admin-routes.go b/api/app-admin-routes.go index 34054e9..323c015 100644 --- a/api/app-admin-routes.go +++ b/api/app-admin-routes.go @@ -174,7 +174,10 @@ func (api *API) appGetAdminLogs(c *gin.Context) { rAdminLogs.Filter = strings.TrimSpace(rAdminLogs.Filter) var jqFilter *gojq.Code - if rAdminLogs.Filter != "" { + var basicFilter string + if strings.HasPrefix(rAdminLogs.Filter, "\"") && strings.HasSuffix(rAdminLogs.Filter, "\"") { + basicFilter = rAdminLogs.Filter[1 : len(rAdminLogs.Filter)-1] + } else if rAdminLogs.Filter != "" { parsed, err := gojq.Parse(rAdminLogs.Filter) if err != nil { log.Error("Unable to parse JQ filter") @@ -220,12 +223,17 @@ func (api *API) appGetAdminLogs(c *gin.Context) { continue } - // No Filter - if jqFilter == nil { + // Basic Filter + if basicFilter != "" && strings.Contains(string(rawData), basicFilter) { logLines = append(logLines, string(rawData)) continue } + // No JQ Filter + if jqFilter == nil { + continue + } + // Error or nil result, _ := jqFilter.Run(jsonMap).Next() if _, ok := result.(error); ok {