소스 검색

add logging information

nallux 2 년 전
부모
커밋
83fb890b07
4개의 변경된 파일12개의 추가작업 그리고 7개의 파일을 삭제
  1. 2 2
      broadcast/broadcast.go
  2. 6 2
      config/config.go
  3. 1 1
      docker/docker.go
  4. 3 2
      docker/netdata.go

+ 2 - 2
broadcast/broadcast.go

@@ -386,11 +386,11 @@ func shipStatusLoop() {
 				config.Logger.Warn(errmsg)
 				continue
 			}
-			mu.Lock()  // Locking the mutex
+			mu.Lock() // Locking the mutex
 			for key, urbit := range updates {
 				broadcastState.Urbits[key] = urbit
 			}
-			mu.Unlock()  // Unlocking the mutex
+			mu.Unlock() // Unlocking the mutex
 			BroadcastToClients()
 		}
 	}

+ 6 - 2
config/config.go

@@ -195,8 +195,12 @@ func UpdateContainerState(name string, containerState structs.ContainerState) {
 	contMutex.Lock()
 	defer contMutex.Unlock()
 	GSContainers[name] = containerState
-	res, _ := json.Marshal(containerState)
-	Logger.Info(fmt.Sprintf("%s:%s", name, string(res)))
+	logMsg := "<hidden>"
+	if DebugMode {
+		res, _ := json.Marshal(containerState)
+		logMsg = string(res)
+	}
+	Logger.Info(fmt.Sprintf("%s state:%s", name, logMsg))
 }
 
 // get the current container state

+ 1 - 1
docker/docker.go

@@ -71,7 +71,7 @@ func GetContainerNetwork(name string) (string, error) {
 	for networkName := range containerJSON.NetworkSettings.Networks {
 		return networkName, nil
 	}
-	return "", fmt.Errorf("container is not attached to any network")
+	return "", fmt.Errorf("container is not attached to any network: %v", name)
 }
 
 // return the disk and memory usage for a container

+ 3 - 2
docker/netdata.go

@@ -2,11 +2,12 @@ package docker
 
 import (
 	"fmt"
-	"github.com/docker/docker/api/types/container"
-	"github.com/docker/go-connections/nat"
 	"goseg/config"
 	"os"
 	"path/filepath"
+
+	"github.com/docker/docker/api/types/container"
+	"github.com/docker/go-connections/nat"
 )
 
 func LoadNetdata() error {