From a6c7eefa397b4e6bae0df98a8c6f4b7551eaba22 Mon Sep 17 00:00:00 2001 From: Ammar Bandukwala Date: Wed, 26 Jul 2023 22:24:39 +0000 Subject: [PATCH] fix(cli): apply log-filter to debug logs only --- cli/server.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cli/server.go b/cli/server.go index 51cac38471ab2..e61c322a10e1c 100644 --- a/cli/server.go +++ b/cli/server.go @@ -1751,14 +1751,14 @@ func IsLocalhost(host string) bool { return host == "localhost" || host == "127.0.0.1" || host == "::1" } -var _ slog.Sink = &filterSink{} +var _ slog.Sink = &debugFilterSink{} -type filterSink struct { +type debugFilterSink struct { next []slog.Sink re *regexp.Regexp } -func (f *filterSink) compile(res []string) error { +func (f *debugFilterSink) compile(res []string) error { if len(res) == 0 { return nil } @@ -1779,17 +1779,19 @@ func (f *filterSink) compile(res []string) error { return nil } -func (f *filterSink) LogEntry(ctx context.Context, ent slog.SinkEntry) { - logName := strings.Join(ent.LoggerNames, ".") - if f.re != nil && !f.re.MatchString(logName) { - return +func (f *debugFilterSink) LogEntry(ctx context.Context, ent slog.SinkEntry) { + if ent.Level == slog.LevelDebug { + logName := strings.Join(ent.LoggerNames, ".") + if f.re != nil && !f.re.MatchString(logName) { + return + } } for _, sink := range f.next { sink.LogEntry(ctx, ent) } } -func (f *filterSink) Sync() { +func (f *debugFilterSink) Sync() { for _, sink := range f.next { sink.Sync() } @@ -1844,7 +1846,7 @@ func BuildLogger(inv *clibase.Invocation, cfg *codersdk.DeploymentValues) (slog. return slog.Logger{}, nil, xerrors.New("no loggers provided") } - filter := &filterSink{next: sinks} + filter := &debugFilterSink{next: sinks} err = filter.compile(cfg.Logging.Filter.Value()) if err != nil { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy