Skip to content

Commit 7312e5e

Browse files
Correct Logging (#215)
* Correct Logging The mirror logging to stdout/err was including the context prefix from python of `[pid=<prediction_id]` this PR eliminates that problem and restores proper logging to console.
1 parent 8768da8 commit 7312e5e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

internal/runner/runner.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,27 @@ func (r *Runner) setupLogCapture() error {
468468
func (r *Runner) logStdout(line string) {
469469
r.captureLogLine(line)
470470

471-
_, _ = fmt.Fprintln(os.Stdout, line) //nolint:forbidigo // mirror log to stdout
471+
// Strip [pid=xxxxx] prefix before mirroring to stdout
472+
mirrorLine := stripPIDPrefix(line)
473+
_, _ = fmt.Fprintln(os.Stdout, mirrorLine) //nolint:forbidigo // mirror log to stdout
472474
}
473475

474476
// logStderr captures a line from stderr and mirrors to stderr
475477
func (r *Runner) logStderr(line string) {
476478
r.captureLogLine(line)
477479

478-
_, _ = fmt.Fprintln(os.Stderr, line) //nolint:forbidigo // mirror log to stderr
480+
// Strip [pid=xxxxx] prefix before mirroring to stderr
481+
mirrorLine := stripPIDPrefix(line)
482+
_, _ = fmt.Fprintln(os.Stderr, mirrorLine) //nolint:forbidigo // mirror log to stderr
483+
}
484+
485+
func stripPIDPrefix(line string) string {
486+
if LogRegex.MatchString(line) {
487+
if m := LogRegex.FindStringSubmatch(line); m != nil {
488+
return m[2] // Extract message without pid prefix
489+
}
490+
}
491+
return line
479492
}
480493

481494
// captureLogLine handles routing log lines like the old implementation

script/test-setuid-cleanup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ python3 -m cog.server.http \
3838
EOF
3939

4040
# Start Docker container
41-
docker run -it --detach \
41+
docker run -it --rm --detach \
4242
--name "$name" \
4343
--entrypoint /bin/bash \
4444
--publish "$port:$port" \

0 commit comments

Comments
 (0)