diff --git a/node/internal/actors/os_procs.go b/node/internal/actors/os_procs.go index 9a84930c..0a8c0109 100644 --- a/node/internal/actors/os_procs.go +++ b/node/internal/actors/os_procs.go @@ -5,6 +5,7 @@ import ( "fmt" "log/slog" "os/exec" + "strings" "github.com/nats-io/nats.go" ) @@ -111,17 +112,17 @@ type logCapture struct { nc *nats.Conn namespace string stderr bool - name string + id string } // Log capture implementation of io.Writer for stdout and stderr func (cap logCapture) Write(p []byte) (n int, err error) { if !cap.stderr { - _ = cap.nc.Publish(fmt.Sprintf("$NEX.logs.%s.%s.stdout", cap.namespace, cap.name), p) - cap.logger.Debug(string(p), slog.String("process_name", cap.name)) + _ = cap.nc.Publish(fmt.Sprintf("$NEX.logs.%s.%s.stdout", cap.namespace, cap.id), p) + cap.logger.Debug(strings.ReplaceAll(string(p), "\n", "\\n")) } else { - _ = cap.nc.Publish(fmt.Sprintf("$NEX.logs.%s.%s.stderr", cap.namespace, cap.name), p) - cap.logger.Error(string(p), slog.String("process_name", cap.name)) + _ = cap.nc.Publish(fmt.Sprintf("$NEX.logs.%s.%s.stderr", cap.namespace, cap.id), p) + cap.logger.Error(strings.ReplaceAll(string(p), "\n", "\\n")) } return len(p), nil } diff --git a/node/internal/actors/process_actor.go b/node/internal/actors/process_actor.go index 062edf89..f322fc71 100644 --- a/node/internal/actors/process_actor.go +++ b/node/internal/actors/process_actor.go @@ -68,8 +68,8 @@ func NewProcessActor(ctx context.Context, logger *slog.Logger, nc *nats.Conn, m triggerSub: m.TriggerSubject, retryCount: int(m.RetryCount), retryCounter: 0, - stdout: logCapture{logger: logger, nc: nc, namespace: m.Namespace, name: m.WorkloadId, stderr: false}, - stderr: logCapture{logger: logger, nc: nc, namespace: m.Namespace, name: m.WorkloadId, stderr: true}, + stdout: logCapture{logger: logger.With(slog.String("id", m.WorkloadId)), nc: nc, namespace: m.Namespace, id: m.WorkloadId, stderr: false}, + stderr: logCapture{logger: logger.With(slog.String("id", m.WorkloadId)), nc: nc, namespace: m.Namespace, id: m.WorkloadId, stderr: true}, } return ret, nil }