1
0
mirror of https://github.com/openshift/installer.git synced 2026-02-05 15:47:14 +01:00
Files
installer/pkg/agent/logging.go
barbacbd ffca92e42a no-jira: Fix linting issues for golangci-lint v2
pkg/agent/logging.go:
QF1006: could lift into loop condition
Skip lint check.

pkg/asset/manifests/azure/cluster.go:
QF1003: could use tagged switch on subnetType
Use a switch instead of if-else

pkg/infrastructure/azure/storage.go:
QF1007: could merge conditional assignment into variable declaration

pkg/infrastructure/baremetal/image.go:
QF1009: probably want to use time.Time.Equal instead
Use function for time.Equal rather than ==.
2025-12-02 11:34:14 -05:00

85 lines
1.5 KiB
Go

package agent
import (
"fmt"
"sync"
"time"
"github.com/sirupsen/logrus"
)
// Constants representing logging levels.
const (
Debug = "Debug"
Info = "Info"
Warning = "Warning"
Trace = "Trace"
Error = "Error"
)
const (
logInterval = 5
)
type logEntry struct {
level string
message string
}
// Uses logger if ch is nil.
func log(level, message string, logger *logrus.Logger, ch chan logEntry) {
if ch != nil {
ch <- logEntry{level: level, message: message}
} else {
switch level {
case Debug:
logger.Debug(message)
case Info:
logger.Info(message)
case Warning:
logger.Warn(message)
case Trace:
logger.Trace(message)
}
}
}
func printChannelLogs(ip string, ch chan logEntry) {
for len(ch) > 0 {
entry := <-ch
message := fmt.Sprintf("Node %s: %s", ip, entry.message)
switch entry.level {
case Debug:
logrus.Debug(message)
case Info:
logrus.Info(message)
case Warning:
logrus.Warn(message)
default:
logrus.Info(message)
}
}
}
func printLogs(wg *sync.WaitGroup, ipChanMap map[string]chan logEntry) {
defer wg.Done()
for {
if len(ipChanMap) == 0 { //nolint: staticcheck
// no IPs to monitor or all channels are closed, exit loop
break
}
for ip, ch := range ipChanMap {
if len(ch) == 0 {
// check if channel is closed
_, ok := <-ch
if !ok {
// channel is closed, remove IP from map to stop checking for logs
delete(ipChanMap, ip)
}
}
printChannelLogs(ip, ch)
}
time.Sleep(logInterval * time.Second)
}
}