logging: include module logs from its parent namespace (#8221)

This commit is contained in:
Omar Ismail 2026-10-16 14:38:15 +03:00 committed by GitHub
parent af7620dcc8
commit 860b4ce635
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View file

@ -550,7 +550,12 @@ func (cl *CustomLog) loggerAllowed(name string, isModule bool) bool {
for _, namespace := range cl.Include {
var hasPrefix bool
if isModule {
hasPrefix = strings.HasPrefix(namespace+".", name)
// the namespace is the module or one of its
// sub-loggers (e.g. "http.log.access" for "http")
hasPrefix = strings.HasPrefix(namespace+".", name) ||
// the namespace is a parent of the module (e.g.
// "http.handlers" for "http.handlers.file_server")
strings.HasPrefix(name, namespace+".")
} else {
hasPrefix = strings.HasPrefix(name, namespace+".")
}

View file

@ -87,6 +87,18 @@ func TestCustomLog_loggerAllowed(t *testing.T) {
},
want: true,
},
{
name: "include module from parent",
fields: fields{
Include: []string{"foo"},
Exclude: []string{},
},
args: args{
name: "foo.bar",
isModule: true,
},
want: true,
},
{
name: "excluded module is not printed",
fields: fields{