refactor(log): split location into package/file/class/method, auto-derived
Per the log schema: 'package' is the Go package (absent on Python-emitted lines), 'file' the Go/Python source basename, 'class' the Go receiver or Python class (omitted when there is none -- free functions no longer masquerade under a package-as-class), 'method' the emitting function. applog.App() now takes no arguments and derives all of it from runtime.Caller, so labels can never drift from the code; the manual http/wrapper emitters and forwarded wrapper.py lines (file= wrapper.py, no package) carry the same fields. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -227,7 +227,9 @@ func (c *subprocessClient) execute(ctx context.Context, cmd string, params any)
|
||||
defer func() {
|
||||
attrs := []slog.Attr{
|
||||
slog.String("type", "wrapper"),
|
||||
slog.String("class", "garmin.subprocessClient"),
|
||||
slog.String("package", "garmin"),
|
||||
slog.String("file", "client.go"),
|
||||
slog.String("class", "subprocessClient"),
|
||||
slog.String("method", "execute"),
|
||||
slog.String("cmd", cmd),
|
||||
slog.Any("params", params),
|
||||
@@ -384,17 +386,18 @@ func forwardWrapperStderr(r io.Reader) {
|
||||
line := scanner.Text()
|
||||
var entry map[string]any
|
||||
if err := json.Unmarshal([]byte(line), &entry); err != nil || entry["msg"] == nil {
|
||||
slog.Warn("", "type", "wrapper", "class", "garmin", "method", "forwardWrapperStderr", "line", line)
|
||||
slog.Warn("", "type", "wrapper", "package", "garmin", "file", "client.go", "method", "forwardWrapperStderr", "line", line)
|
||||
continue
|
||||
}
|
||||
msg, _ := entry["msg"].(string)
|
||||
levelName, _ := entry["level"].(string)
|
||||
delete(entry, "msg")
|
||||
delete(entry, "level")
|
||||
// class is the Python module; method arrives in the entry itself
|
||||
// Python-emitted lines carry no "package" (a Go-only field) and no
|
||||
// "class" (wrapper.py has none); method arrives in the entry itself
|
||||
// (wrapper.py's _log stamps the emitting function).
|
||||
attrs := make([]slog.Attr, 0, len(entry)+2)
|
||||
attrs = append(attrs, slog.String("type", "wrapper"), slog.String("class", "wrapper"))
|
||||
attrs = append(attrs, slog.String("type", "wrapper"), slog.String("file", "wrapper.py"))
|
||||
for k, v := range entry {
|
||||
attrs = append(attrs, slog.Any(k, v))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user