fix(logging): raise the input logger to debug when input-motion is selected
- commit
- 1d6f9968271291b82ab4211e9041c6acb7ca6393
- author
- brice · · 2026-09-26 12:27 UTC
- parent
- d40a34e
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +30 -2
M internal/logging/logging.go +8 -2
| @@ -22,7 +22,8 @@ var components = map[string]bool{ | |||
| 22 | 22 | ||
| 23 | 23 | // categories are debug switches narrower than a component, only on when | |
| 24 | 24 | // named: "all" leaves them off (input-motion logs every pointer motion). | |
| 25 | - | var categories = map[string]bool{"input-motion": true} | |
| 25 | + | // Naming one turns on debug for its component. | |
| 26 | + | var categories = map[string]string{"input-motion": "input"} | |
| 26 | 27 | ||
| 27 | 28 | type debugKey struct{} | |
| 28 | 29 | type levelKey struct{} | |
| @@ -38,7 +39,7 @@ func ParseDebug(value string) (map[string]bool, error) { | |||
| 38 | 39 | selected[name] = true | |
| 39 | 40 | continue | |
| 40 | 41 | } | |
| 41 | - | if !components[name] && !categories[name] { | |
| 42 | + | if _, ok := categories[name]; !components[name] && !ok { | |
| 42 | 43 | return nil, fmt.Errorf("invalid debug component %q", name) | |
| 43 | 44 | } | |
| 44 | 45 | selected[name] = true | |
| @@ -130,6 +131,11 @@ func For(ctx context.Context, component string) zerowrap.Logger { | |||
| 130 | 131 | if selected["all"] || selected[component] { | |
| 131 | 132 | level = zerolog.DebugLevel | |
| 132 | 133 | } | |
| 134 | + | for name, owner := range categories { | |
| 135 | + | if selected[name] && owner == component { | |
| 136 | + | level = zerolog.DebugLevel | |
| 137 | + | } | |
| 138 | + | } | |
| 133 | 139 | log = zerowrap.Logger{Logger: log.Level(level)} | |
| 134 | 140 | return log | |
| 135 | 141 | } | |
| @@ -22,7 +22,8 @@ var components = map[string]bool{ | |||||
| 22 | 22 | ||||
| 23 | // categories are debug switches narrower than a component, only on when | 23 | // categories are debug switches narrower than a component, only on when | ||
| 24 | // named: "all" leaves them off (input-motion logs every pointer motion). | 24 | // named: "all" leaves them off (input-motion logs every pointer motion). | ||
| 25 | - | var categories = map[string]bool{"input-motion": true} | 25 | + | // Naming one turns on debug for its component. |
| 26 | + | var categories = map[string]string{"input-motion": "input"} | |||
| 26 | 27 | ||||
| 27 | type debugKey struct{} | 28 | type debugKey struct{} | ||
| 28 | type levelKey struct{} | 29 | type levelKey struct{} | ||
| @@ -38,7 +39,7 @@ func ParseDebug(value string) (map[string]bool, error) { | |||||
| 38 | selected[name] = true | 39 | selected[name] = true | ||
| 39 | continue | 40 | continue | ||
| 40 | } | 41 | } | ||
| 41 | - | if !components[name] && !categories[name] { | 42 | + | if _, ok := categories[name]; !components[name] && !ok { |
| 42 | return nil, fmt.Errorf("invalid debug component %q", name) | 43 | return nil, fmt.Errorf("invalid debug component %q", name) | ||
| 43 | } | 44 | } | ||
| 44 | selected[name] = true | 45 | selected[name] = true | ||
| @@ -130,6 +131,11 @@ func For(ctx context.Context, component string) zerowrap.Logger { | |||||
| 130 | if selected["all"] || selected[component] { | 131 | if selected["all"] || selected[component] { | ||
| 131 | level = zerolog.DebugLevel | 132 | level = zerolog.DebugLevel | ||
| 132 | } | 133 | } | ||
| 134 | + | for name, owner := range categories { | |||
| 135 | + | if selected[name] && owner == component { | |||
| 136 | + | level = zerolog.DebugLevel | |||
| 137 | + | } | |||
| 138 | + | } | |||
| 133 | log = zerowrap.Logger{Logger: log.Level(level)} | 139 | log = zerowrap.Logger{Logger: log.Level(level)} | ||
| 134 | return log | 140 | return log | ||
| 135 | } | 141 | } | ||
M internal/logging/logging_test.go +22 -0
| @@ -84,6 +84,28 @@ func splitLines(data []byte) [][]byte { | |||
| 84 | 84 | return lines | |
| 85 | 85 | } | |
| 86 | 86 | ||
| 87 | + | // A category alone raises its component to debug, so its lines are written. | |
| 88 | + | func TestCategoryEnablesComponentDebug(t *testing.T) { | |
| 89 | + | t.Setenv("XDG_STATE_HOME", t.TempDir()) | |
| 90 | + | ctx, closeLog, err := Open(context.Background(), "info", "input-motion") | |
| 91 | + | if err != nil { | |
| 92 | + | t.Fatal(err) | |
| 93 | + | } | |
| 94 | + | input, core := For(ctx, "input"), For(ctx, "core") | |
| 95 | + | input.Debug().Msg("motion") | |
| 96 | + | core.Debug().Msg("hidden") | |
| 97 | + | if err := closeLog(); err != nil { | |
| 98 | + | t.Fatal(err) | |
| 99 | + | } | |
| 100 | + | data, err := os.ReadFile(filepath.Join(os.Getenv("XDG_STATE_HOME"), "nefertty", "runs", "latest.log")) | |
| 101 | + | if err != nil { | |
| 102 | + | t.Fatal(err) | |
| 103 | + | } | |
| 104 | + | if lines := splitLines(data); len(lines) != 1 || !bytes.Contains(lines[0], []byte(`"motion"`)) { | |
| 105 | + | t.Fatalf("got %q", data) | |
| 106 | + | } | |
| 107 | + | } | |
| 108 | + | ||
| 87 | 109 | // Narrow categories are on only when named, never through "all". | |
| 88 | 110 | func TestEnabledCategories(t *testing.T) { | |
| 89 | 111 | for _, tc := range []struct { | |
| @@ -84,6 +84,28 @@ func splitLines(data []byte) [][]byte { | |||||
| 84 | return lines | 84 | return lines | ||
| 85 | } | 85 | } | ||
| 86 | 86 | ||||
| 87 | + | // A category alone raises its component to debug, so its lines are written. | |||
| 88 | + | func TestCategoryEnablesComponentDebug(t *testing.T) { | |||
| 89 | + | t.Setenv("XDG_STATE_HOME", t.TempDir()) | |||
| 90 | + | ctx, closeLog, err := Open(context.Background(), "info", "input-motion") | |||
| 91 | + | if err != nil { | |||
| 92 | + | t.Fatal(err) | |||
| 93 | + | } | |||
| 94 | + | input, core := For(ctx, "input"), For(ctx, "core") | |||
| 95 | + | input.Debug().Msg("motion") | |||
| 96 | + | core.Debug().Msg("hidden") | |||
| 97 | + | if err := closeLog(); err != nil { | |||
| 98 | + | t.Fatal(err) | |||
| 99 | + | } | |||
| 100 | + | data, err := os.ReadFile(filepath.Join(os.Getenv("XDG_STATE_HOME"), "nefertty", "runs", "latest.log")) | |||
| 101 | + | if err != nil { | |||
| 102 | + | t.Fatal(err) | |||
| 103 | + | } | |||
| 104 | + | if lines := splitLines(data); len(lines) != 1 || !bytes.Contains(lines[0], []byte(`"motion"`)) { | |||
| 105 | + | t.Fatalf("got %q", data) | |||
| 106 | + | } | |||
| 107 | + | } | |||
| 108 | + | ||||
| 87 | // Narrow categories are on only when named, never through "all". | 109 | // Narrow categories are on only when named, never through "all". | ||
| 88 | func TestEnabledCategories(t *testing.T) { | 110 | func TestEnabledCategories(t *testing.T) { | ||
| 89 | for _, tc := range []struct { | 111 | for _, tc := range []struct { | ||