Skip to content

Commit 02550a9

Browse files
authored
fix(cli): apply log-filter to debug logs only (#8751)
1 parent 131babf commit 02550a9

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

cli/server.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,14 +1751,14 @@ func IsLocalhost(host string) bool {
17511751
return host == "localhost" || host == "127.0.0.1" || host == "::1"
17521752
}
17531753

1754-
var _ slog.Sink = &filterSink{}
1754+
var _ slog.Sink = &debugFilterSink{}
17551755

1756-
type filterSink struct {
1756+
type debugFilterSink struct {
17571757
next []slog.Sink
17581758
re *regexp.Regexp
17591759
}
17601760

1761-
func (f *filterSink) compile(res []string) error {
1761+
func (f *debugFilterSink) compile(res []string) error {
17621762
if len(res) == 0 {
17631763
return nil
17641764
}
@@ -1779,17 +1779,19 @@ func (f *filterSink) compile(res []string) error {
17791779
return nil
17801780
}
17811781

1782-
func (f *filterSink) LogEntry(ctx context.Context, ent slog.SinkEntry) {
1783-
logName := strings.Join(ent.LoggerNames, ".")
1784-
if f.re != nil && !f.re.MatchString(logName) {
1785-
return
1782+
func (f *debugFilterSink) LogEntry(ctx context.Context, ent slog.SinkEntry) {
1783+
if ent.Level == slog.LevelDebug {
1784+
logName := strings.Join(ent.LoggerNames, ".")
1785+
if f.re != nil && !f.re.MatchString(logName) {
1786+
return
1787+
}
17861788
}
17871789
for _, sink := range f.next {
17881790
sink.LogEntry(ctx, ent)
17891791
}
17901792
}
17911793

1792-
func (f *filterSink) Sync() {
1794+
func (f *debugFilterSink) Sync() {
17931795
for _, sink := range f.next {
17941796
sink.Sync()
17951797
}
@@ -1844,7 +1846,7 @@ func BuildLogger(inv *clibase.Invocation, cfg *codersdk.DeploymentValues) (slog.
18441846
return slog.Logger{}, nil, xerrors.New("no loggers provided")
18451847
}
18461848

1847-
filter := &filterSink{next: sinks}
1849+
filter := &debugFilterSink{next: sinks}
18481850

18491851
err = filter.compile(cfg.Logging.Filter.Value())
18501852
if err != nil {

0 commit comments

Comments
 (0)