60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package children
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"isle/toolkit"
|
|
|
|
"code.betamike.com/micropelago/pmux/pmuxlib"
|
|
"dev.mediocregopher.com/mediocre-go-lib.git/mlog"
|
|
)
|
|
|
|
type pmuxLogger struct {
|
|
ctx context.Context
|
|
logger *mlog.Logger
|
|
}
|
|
|
|
func newPmuxStdoutLogger(
|
|
ctx context.Context, logger *mlog.Logger, name string,
|
|
) pmuxlib.Logger {
|
|
return &pmuxLogger{ctx, logger.WithNamespace(name).WithNamespace("out")}
|
|
}
|
|
|
|
func newPmuxStderrLogger(
|
|
ctx context.Context, logger *mlog.Logger, name string,
|
|
) pmuxlib.Logger {
|
|
return &pmuxLogger{ctx, logger.WithNamespace(name).WithNamespace("err")}
|
|
}
|
|
|
|
func newPmuxSysLogger(
|
|
ctx context.Context, logger *mlog.Logger, name string,
|
|
) pmuxlib.Logger {
|
|
return &pmuxLogger{ctx, logger.WithNamespace(name).WithNamespace("sys")}
|
|
}
|
|
|
|
func (l *pmuxLogger) Println(line string) {
|
|
l.logger.Log(mlog.Message{
|
|
Context: l.ctx,
|
|
Level: toolkit.LogLevelChild,
|
|
Description: line,
|
|
})
|
|
}
|
|
|
|
func (l *pmuxLogger) Printf(format string, args ...any) {
|
|
l.Println(fmt.Sprintf(format, args...))
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
func withPmuxLoggers(
|
|
ctx context.Context,
|
|
logger *mlog.Logger,
|
|
name string,
|
|
cfg pmuxlib.ProcessConfig,
|
|
) pmuxlib.ProcessConfig {
|
|
cfg.StdoutLogger = newPmuxStdoutLogger(ctx, logger, name)
|
|
cfg.StderrLogger = newPmuxStderrLogger(ctx, logger, name)
|
|
cfg.SysLogger = newPmuxSysLogger(ctx, logger, name)
|
|
return cfg
|
|
}
|