Skip to content

Commit f9009b9

Browse files
committed
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 22c158d commit f9009b9

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

internal/runner/runner.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,28 @@ 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 := line
473+
if LogRegex.MatchString(line) {
474+
if m := LogRegex.FindStringSubmatch(line); m != nil {
475+
mirrorLine = m[2] // Extract message without pid prefix
476+
}
477+
}
478+
_, _ = fmt.Fprintln(os.Stdout, mirrorLine) //nolint:forbidigo // mirror log to stdout
472479
}
473480

474481
// logStderr captures a line from stderr and mirrors to stderr
475482
func (r *Runner) logStderr(line string) {
476483
r.captureLogLine(line)
477484

478-
_, _ = fmt.Fprintln(os.Stderr, line) //nolint:forbidigo // mirror log to stderr
485+
// Strip [pid=xxxxx] prefix before mirroring to stderr
486+
mirrorLine := line
487+
if LogRegex.MatchString(line) {
488+
if m := LogRegex.FindStringSubmatch(line); m != nil {
489+
mirrorLine = m[2] // Extract message without pid prefix
490+
}
491+
}
492+
_, _ = fmt.Fprintln(os.Stderr, mirrorLine) //nolint:forbidigo // mirror log to stderr
479493
}
480494

481495
// 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)