From 6c3bd124cebea5c25a9b6e00d1260dabc8bf82d5 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Tue, 9 Jan 2024 22:15:42 +1100 Subject: [PATCH] Added option to disable AssetServer logging. An option to disable AssetServer logging has been introduced in the application options. This will suppress every request log from the AssetServer if set to true. This adjustment is useful for preventing log saturation in certain scenarios or environments. --- v3/pkg/application/application.go | 7 ++++++- v3/pkg/application/options_application.go | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/v3/pkg/application/application.go b/v3/pkg/application/application.go index 65b33d5bca9..7215accb90f 100644 --- a/v3/pkg/application/application.go +++ b/v3/pkg/application/application.go @@ -74,7 +74,12 @@ func New(appOptions Options) *App { Middleware: assetserver.Middleware(appOptions.Assets.Middleware), } - srv, err := assetserver.NewAssetServer(opts, false, result.Logger, wailsruntime.RuntimeAssetsBundle, result.isDebugMode, NewMessageProcessor(result.Logger)) + assetLogger := result.Logger + if appOptions.Assets.DisableLogging { + assetLogger = slog.New(slog.NewTextHandler(io.Discard, nil)) + } + + srv, err := assetserver.NewAssetServer(opts, false, assetLogger, wailsruntime.RuntimeAssetsBundle, result.isDebugMode, NewMessageProcessor(result.Logger)) if err != nil { result.Logger.Error("Fatal error in application initialisation: " + err.Error()) os.Exit(1) diff --git a/v3/pkg/application/options_application.go b/v3/pkg/application/options_application.go index ad5db123d6d..5ee2afe35ab 100644 --- a/v3/pkg/application/options_application.go +++ b/v3/pkg/application/options_application.go @@ -80,6 +80,9 @@ type AssetOptions struct { // Multiple Middlewares can be chained together with: // ChainMiddleware(middleware ...Middleware) Middleware Middleware Middleware + + // DisableLogging disables logging of the AssetServer. By default, the AssetServer logs every request. + DisableLogging bool } // Middleware defines HTTP middleware that can be applied to the AssetServer.