Skip to content

Commit

Permalink
Updated log var and implemented log levels
Browse files Browse the repository at this point in the history
  • Loading branch information
matoval committed Sep 21, 2024
1 parent 1840fc1 commit f8d0a6c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
27 changes: 16 additions & 11 deletions pkg/controlsvc/controlsvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"os"
"reflect"
"runtime"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -123,33 +124,37 @@ func (s *SockControl) ReadFromConn(message string, out io.Writer, io Copier) err
if err := s.WriteMessage(message); err != nil {
return err
}
isPayloadDebug := os.Getenv("RECEPTOR_PAYLOAD_DEBUG")
if isPayloadDebug != "" {
payloadDebug, _ := strconv.Atoi(os.Getenv("RECEPTOR_PAYLOAD_TRACE_LEVEL"))
switch {
case payloadDebug > 2:
var data string
reader := bufio.NewReader(s.conn)

for {
var connectType string
if s.conn.LocalAddr().Network() == "unix" {
connectType = "unix socket"
} else {
connectType = "network connection"
}
response, err := reader.ReadString('\n')
if err != nil {
if err.Error() != "EOF" {
MainInstance.nc.GetLogger().Error("Error reading from %v: %v \n", connectType, err)
MainInstance.nc.GetLogger().Error("Error reading from conn: %v \n", err)
}

break
}
data += response
MainInstance.nc.GetLogger().Debug("Response from %v: %v", connectType, response)
MainInstance.nc.GetLogger().Debug("Response reading from conn: %v", response)
}
if _, err := out.Write([]byte(data)); err != nil {
return err
}
} else {
fallthrough

Check failure on line 148 in pkg/controlsvc/controlsvc.go

View workflow job for this annotation

GitHub Actions / lint-receptor

fallthrough with no blank line before (nlreturn)
case payloadDebug > 0:
var connectType string
if s.conn.LocalAddr().Network() == "unix" {
connectType = "unix socket"
} else {
connectType = "network connection"
}
MainInstance.nc.GetLogger().Debug("Reading from %v", connectType)
default:
if _, err := io.Copy(out, s.conn); err != nil {
return err
}
Expand Down
15 changes: 10 additions & 5 deletions pkg/workceptor/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os/exec"
"os/signal"
"path"
"strconv"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -114,11 +115,12 @@ func commandRunner(command string, params string, unitdir string) error {
if err != nil {
return err
}
isPayloadDebug := os.Getenv("RECEPTOR_PAYLOAD_DEBUG")
if isPayloadDebug != "" {
payloadDebug, _ := strconv.Atoi(os.Getenv("RECEPTOR_PAYLOAD_TRACE_LEVEL"))
splitUnitDir := strings.Split(unitdir, "/")
workUnitID := splitUnitDir[len(splitUnitDir)-1]
switch payloadDebug {
case 3:
var data string
splitUnitDir := strings.Split(unitdir, "/")
workUnitID := splitUnitDir[len(splitUnitDir)-1]
reader := bufio.NewReader(stdin)
stdinStream, err := cmd.StdinPipe()
if err != nil {
Expand All @@ -137,7 +139,10 @@ func commandRunner(command string, params string, unitdir string) error {
MainInstance.nc.GetLogger().Debug("Work unit %v stdin: %v", workUnitID, response)
}
io.WriteString(stdinStream, data)
} else {
case 2:
MainInstance.nc.GetLogger().Debug("Work unit %v received command\n", workUnitID)
cmd.Stdin = stdin
default:
cmd.Stdin = stdin
}
stdout, err := os.OpenFile(path.Join(unitdir, "stdout"), os.O_CREATE+os.O_WRONLY+os.O_SYNC, 0o600)
Expand Down

0 comments on commit f8d0a6c

Please sign in to comment.