Pass stdout/stderr into pmuxlib.Run

This commit is contained in:
Brian Picciano 2022-10-25 20:54:05 +02:00
parent 7a78680038
commit 29241f144a
2 changed files with 9 additions and 5 deletions

View File

@ -43,5 +43,5 @@ func main() {
os.Exit(1) os.Exit(1)
}() }()
pmuxlib.Run(ctx, cfg) pmuxlib.Run(ctx, os.Stdout, os.Stderr, cfg)
} }

View File

@ -4,7 +4,7 @@ package pmuxlib
import ( import (
"context" "context"
"os" "io"
"sync" "sync"
) )
@ -16,12 +16,16 @@ type Config struct {
// Run runs the given configuration as if this was a real pmux process. It will // Run runs the given configuration as if this was a real pmux process. It will
// block until the context is canceled and all child processes have been cleaned // block until the context is canceled and all child processes have been cleaned
// up. // up.
func Run(ctx context.Context, cfg Config) { func Run(
ctx context.Context,
stdout, stderr io.Writer,
cfg Config,
) {
stdoutLogger := newLogger(os.Stdout, logSepStdout, cfg.TimeFormat) stdoutLogger := newLogger(stdout, logSepStdout, cfg.TimeFormat)
defer stdoutLogger.Close() defer stdoutLogger.Close()
stderrLogger := newLogger(os.Stderr, logSepStderr, cfg.TimeFormat) stderrLogger := newLogger(stderr, logSepStderr, cfg.TimeFormat)
defer stderrLogger.Close() defer stderrLogger.Close()
sysLogger := stderrLogger.withSep(logSepSys) sysLogger := stderrLogger.withSep(logSepSys)