[client] Use the netbird logger for ice and grpc (#3603)

updates the logging implementation to use the netbird logger for both ICE and gRPC components. The key changes include:

- Introducing a gRPC logger configuration in util/log.go that integrates with the netbird logging setup.
- Updating the log hook in formatter/hook/hook.go to ensure a default caller is used when not set.
- Refactoring ICE agent and UDP multiplexers to use a unified logger via the new getLogger() method.
This commit is contained in:
Maycon Santos
2025-04-04 18:30:47 +02:00
committed by GitHub
parent 80702b9323
commit fbd783ad58
5 changed files with 40 additions and 4 deletions

View File

@ -8,6 +8,7 @@ import (
"strconv"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc/grpclog"
"gopkg.in/natefinch/lumberjack.v2"
"github.com/netbirdio/netbird/formatter"
@ -48,9 +49,28 @@ func InitLog(logLevel string, logPath string) error {
formatter.SetTextFormatter(log.StandardLogger())
}
log.SetLevel(level)
setGRPCLibLogger()
return nil
}
func setGRPCLibLogger() {
logOut := log.StandardLogger().Writer()
if os.Getenv("GRPC_GO_LOG_SEVERITY_LEVEL") != "info" {
grpclog.SetLoggerV2(grpclog.NewLoggerV2(io.Discard, logOut, logOut))
return
}
var v int
vLevel := os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL")
if vl, err := strconv.Atoi(vLevel); err == nil {
v = vl
}
grpclog.SetLoggerV2(grpclog.NewLoggerV2WithVerbosity(logOut, logOut, logOut, v))
}
func getLogMaxSize() int {
if sizeVar, ok := os.LookupEnv("NB_LOG_MAX_SIZE_MB"); ok {
size, err := strconv.ParseInt(sizeVar, 10, 64)