Skip to content

Commit

Permalink
clean up log EOL space
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Rash <jordan@synadia.com>
  • Loading branch information
jordan-rash committed Dec 27, 2024
1 parent 31b89d5 commit 421f7e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions node/internal/actors/os_procs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log/slog"
"os/exec"
"strings"

"github.com/nats-io/nats.go"
)
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions node/internal/actors/process_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 421f7e3

Please sign in to comment.