Logging: structured slog messages throughout, and WithLogger options so callers choose the logger
Log messages are lower-case event names with their details as key/value
attributes ("error" for errors), in place of formatted strings.
Loggable package take a WithLogger option as part of their "New*" call,
defaulting to slog.Default(). Each tags its lines with its `component`.
Some debug loggers print directly rather than using slog when in
terminal logging mode.
This commit is contained in:
1 parent
0b5fde9563
commit
043e307663
49 files changed
+598
-248
No files matched your search
@@ -108,15 +108,15 @@ func TestPrintLog(t *testing.T) {
|
||||
t.Errorf("PrintLog(%v) line %q; want %s", tt.at, l, tt.want)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(logs.String(), "logging.level = warn") {
|
||||
if !strings.Contains(logs.String(), "key=logging.level value=warn") {
|
||||
t.Errorf("PrintLog(%v) missing logging.level:\n%s", tt.at, logs)
|
||||
}
|
||||
// Each line is msg="\t<key> = <value>".
|
||||
// Each line is msg="config value" key=<key> value=<value>.
|
||||
flat := conf.Flatten()
|
||||
var keys []string
|
||||
for _, l := range lines {
|
||||
_, msg, _ := strings.Cut(l, `msg="\t`)
|
||||
key, _, _ := strings.Cut(msg, " = ")
|
||||
_, rest, _ := strings.Cut(l, ` key=`)
|
||||
key, _, _ := strings.Cut(rest, " ")
|
||||
if _, ok := flat[key]; !ok {
|
||||
t.Errorf("PrintLog(%v) line %q: no key", tt.at, l)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user