* small change for zap log restruct
This commit is contained in:
Paul Yu 2023-09-19 19:02:28 -04:00 коммит произвёл GitHub
Родитель 477200881d
Коммит 246fee4bd0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
20 изменённых файлов: 59 добавлений и 144 удалений

Просмотреть файл

@ -9,10 +9,7 @@ import (
"go.uber.org/zap"
)
var (
loggerName = "azure-vnet"
logger = log.InitZapLogCNI(loggerName, "azure-vnet.log")
)
var logger = log.CNILogger.With(zap.String("component", "cni-api"))
type PodNetworkInterfaceInfo struct {
PodName string

Просмотреть файл

@ -16,10 +16,7 @@ import (
utilexec "k8s.io/utils/exec"
)
var (
loggerName = "azure-vnet-client"
logger = log.InitZapLogCNI(loggerName, "azure-vnet.log")
)
var logger = log.CNILogger.With(zap.String("component", "cni-client"))
type client struct {
exec utilexec.Interface

Просмотреть файл

@ -21,10 +21,7 @@ import (
const ipamV6 = "azure-vnet-ipamv6"
var (
loggerName = "azure-vnet-ipam"
logger = log.InitZapLogCNI(loggerName, "azure-ipam.log")
)
var logger = log.IPamLogger.With(zap.String("component", "cni-ipam"))
var ipv4DefaultRouteDstPrefix = net.IPNet{
IP: net.IPv4zero,

Просмотреть файл

@ -3,17 +3,40 @@ package log
import (
"os"
"github.com/Azure/azure-container-networking/zaplog"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"gopkg.in/natefinch/lumberjack.v2"
)
func InitZapLogCNI(loggerName, loggerFile string) *zap.Logger {
zaplog.LoggerCfg.Name = loggerName
zaplog.LoggerCfg.LogPath = zaplog.LogPath + loggerFile
logger := zaplog.InitZapLog(&zaplog.LoggerCfg)
var (
zapCNILogFile = "azure-vnet.log"
zapIpamLogFile = "azure-vnet-ipam.log"
zapTelemetryLogFile = "azure-vnet-telemetry.log"
)
// only log process id on CNI package
logger = logger.With(zap.Int("pid", os.Getpid()))
logger = logger.With(zap.String("component", "cni"))
return logger
const (
maxLogFileSizeInMb = 5
maxLogFileCount = 8
)
func initZapLog(logFile string) *zap.Logger {
logFileCNIWriter := zapcore.AddSync(&lumberjack.Logger{
Filename: LogPath + logFile,
MaxSize: maxLogFileSizeInMb,
MaxBackups: maxLogFileCount,
})
encoderConfig := zap.NewProductionEncoderConfig()
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
jsonEncoder := zapcore.NewJSONEncoder(encoderConfig)
core := zapcore.NewCore(jsonEncoder, logFileCNIWriter, zapcore.DebugLevel)
Logger := zap.New(core)
return Logger
}
var (
CNILogger = initZapLog(zapCNILogFile).With(zap.Int("pid", os.Getpid()))
IPamLogger = initZapLog(zapIpamLogFile).With(zap.Int("pid", os.Getpid()))
TelemetryLogger = initZapLog(zapTelemetryLogFile).With(zap.Int("pid", os.Getpid()))
)

Просмотреть файл

@ -1,4 +1,4 @@
package zaplog
package log
const (
// LogPath is the path where log files are stored.

Просмотреть файл

@ -1,5 +1,7 @@
package log
import "go.uber.org/zap"
func InitializeMock() {
InitZapLogCNI("azure-vnet", "")
CNILogger.With(zap.String("component", "cni"))
}

Просмотреть файл

@ -1,4 +1,4 @@
package zaplog
package log
const (
// LogPath is the path where log files are stored.

Просмотреть файл

@ -19,10 +19,7 @@ import (
"go.uber.org/zap"
)
var (
loggerName = "azure-vnet"
logger = log.InitZapLogCNI(loggerName, "azure-vnet.log")
)
var logger = log.CNILogger.With(zap.String("component", "cni-net"))
const (
bytesSize4 = 4

Просмотреть файл

@ -14,7 +14,7 @@ import (
"github.com/Azure/azure-container-networking/aitelemetry"
"github.com/Azure/azure-container-networking/cni"
"github.com/Azure/azure-container-networking/cni/api"
zapLog "github.com/Azure/azure-container-networking/cni/log"
zaplog "github.com/Azure/azure-container-networking/cni/log"
"github.com/Azure/azure-container-networking/cni/network"
"github.com/Azure/azure-container-networking/common"
"github.com/Azure/azure-container-networking/log"
@ -40,7 +40,7 @@ const (
// Version is populated by make during build.
var version string
var logger = zapLog.InitZapLogCNI(name, "azure-vnet.log")
var logger = zaplog.CNILogger.With(zap.String("component", "cni-main"))
// Command line arguments for CNI plugin.
var args = common.ArgumentList{

Просмотреть файл

@ -24,10 +24,7 @@ import (
"go.uber.org/zap"
)
var (
loggerName = "azure-vnet"
logger = log.InitZapLogCNI(loggerName, "azure-vnet.log")
)
var logger = log.CNILogger.With(zap.String("component", "cni-plugin"))
var errEmptyContent = errors.New("read content is zero bytes")

Просмотреть файл

@ -13,7 +13,6 @@ import (
"github.com/Azure/azure-container-networking/cni/log"
acn "github.com/Azure/azure-container-networking/common"
"github.com/Azure/azure-container-networking/telemetry"
"github.com/Azure/azure-container-networking/zaplog"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
@ -108,7 +107,6 @@ func main() {
var err error
acn.ParseArgs(&args, printVersion)
logLevel := acn.GetArg(acn.OptLogLevel).(zapcore.Level)
configDirectory := acn.GetArg(acn.OptTelemetryConfigDir).(string)
vers := acn.GetArg(acn.OptVersion).(bool)
@ -117,8 +115,7 @@ func main() {
os.Exit(0)
}
zaplog.LoggerCfg.Level = logLevel
logger := log.InitZapLogCNI(azureVnetTelemetry, azureVnetTelemetry+".log")
logger := log.TelemetryLogger.With(zap.String("component", "cni-telemetry"))
logger.Info("Telemetry invocation info", zap.Any("arguments", os.Args))
@ -177,5 +174,4 @@ func main() {
logger.Info("[Telemetry] Report to host interval", zap.Duration("seconds", config.ReportToHostIntervalInSeconds))
tb.PushData(context.Background())
telemetry.CloseAITelemetryHandle()
}

Просмотреть файл

@ -9,9 +9,9 @@ import (
"net"
"strings"
"github.com/Azure/azure-container-networking/cni/log"
"github.com/Azure/azure-container-networking/netio"
"github.com/Azure/azure-container-networking/netlink"
"github.com/Azure/azure-container-networking/network/log"
"github.com/Azure/azure-container-networking/network/policy"
"github.com/Azure/azure-container-networking/platform"
"go.uber.org/zap"
@ -21,10 +21,7 @@ const (
InfraVnet = 0
)
var (
loggerName = "net"
logger = log.InitZapLogNet(loggerName)
)
var logger = log.CNILogger.With(zap.String("component", "net"))
type AzureHNSEndpoint struct{}

Просмотреть файл

@ -6,15 +6,12 @@ package hnswrapper
import (
"encoding/json"
"github.com/Azure/azure-container-networking/network/log"
"github.com/Azure/azure-container-networking/cni/log"
"github.com/Microsoft/hcsshim"
"go.uber.org/zap"
)
var (
loggerName = "net"
logger = log.InitZapLogNet(loggerName)
)
var logger = log.CNILogger.With(zap.String("component", "net-hns"))
type Hnsv1wrapper struct{}

Просмотреть файл

@ -1,20 +0,0 @@
package log
import (
"os"
"github.com/Azure/azure-container-networking/zaplog"
"go.uber.org/zap"
)
var loggerFile = "azure-vnet.log"
func InitZapLogNet(loggerName string) *zap.Logger {
zaplog.LoggerCfg.Name = loggerName
zaplog.LoggerCfg.LogPath = zaplog.LogPath + loggerFile
logger := zaplog.InitZapLog(&zaplog.LoggerCfg)
// only log process id on CNI package
logger = logger.With(zap.Int("pid", os.Getpid()))
return logger
}

Просмотреть файл

@ -7,9 +7,9 @@ import (
"fmt"
"net"
"github.com/Azure/azure-container-networking/cni/log"
"github.com/Azure/azure-container-networking/iptables"
"github.com/Azure/azure-container-networking/netlink"
"github.com/Azure/azure-container-networking/network/log"
"github.com/Azure/azure-container-networking/platform"
"github.com/pkg/errors"
"go.uber.org/zap"
@ -38,10 +38,7 @@ const (
acceptRAV6File = "/proc/sys/net/ipv6/conf/%s/accept_ra"
)
var (
loggerName = "net"
logger = log.InitZapLogNet(loggerName)
)
var logger = log.CNILogger.With(zap.String("component", "net-utils"))
var errorNetworkUtils = errors.New("NetworkUtils Error")

Просмотреть файл

@ -8,18 +8,15 @@ import (
"fmt"
"net"
"github.com/Azure/azure-container-networking/cni/log"
"github.com/Azure/azure-container-networking/netlink"
"github.com/Azure/azure-container-networking/network/log"
"github.com/Azure/azure-container-networking/network/networkutils"
"github.com/Azure/azure-container-networking/ovsctl"
"github.com/Azure/azure-container-networking/platform"
"go.uber.org/zap"
)
var (
loggerName = "net"
logger = log.InitZapLogNet(loggerName)
)
var logger = log.CNILogger.With(zap.String("component", "net"))
const (
azureInfraIfName = "eth2"

Просмотреть файл

@ -5,7 +5,7 @@ import (
"fmt"
"net"
"github.com/Azure/azure-container-networking/network/log"
"github.com/Azure/azure-container-networking/cni/log"
"github.com/Azure/azure-container-networking/network/networkutils"
"github.com/Microsoft/hcsshim"
"github.com/Microsoft/hcsshim/hcn"
@ -13,10 +13,7 @@ import (
"go.uber.org/zap"
)
var (
loggerName = "policy"
logger = log.InitZapLogNet(loggerName)
)
var logger = log.CNILogger.With(zap.String("component", "net-policy"))
const (
// ProtocolTcp indicates tcp protocol id for portmapping

Просмотреть файл

@ -8,10 +8,10 @@ import (
"net"
"strings"
"github.com/Azure/azure-container-networking/cni/log"
"github.com/Azure/azure-container-networking/ebtables"
"github.com/Azure/azure-container-networking/iptables"
"github.com/Azure/azure-container-networking/netlink"
"github.com/Azure/azure-container-networking/network/log"
"github.com/Azure/azure-container-networking/network/networkutils"
"github.com/Azure/azure-container-networking/platform"
"github.com/pkg/errors"
@ -28,10 +28,7 @@ const (
l2PreroutingEntries = "ebtables -t nat -L PREROUTING"
)
var (
loggerName = "net"
logger = log.InitZapLogNet(loggerName)
)
var logger = log.CNILogger.With(zap.String("component", "net"))
var errorSnatClient = errors.New("SnatClient Error")

Просмотреть файл

@ -9,16 +9,13 @@ import (
"net"
"strings"
"github.com/Azure/azure-container-networking/cni/log"
"github.com/Azure/azure-container-networking/common"
"github.com/Azure/azure-container-networking/network/log"
"github.com/Azure/azure-container-networking/platform"
"go.uber.org/zap"
)
var (
loggerName = "ovs"
logger = log.InitZapLogNet(loggerName)
)
var logger = log.CNILogger.With(zap.String("component", "ovs"))
const (
defaultMacForArpResponse = "12:34:56:78:9a:bc"

Просмотреть файл

@ -1,50 +0,0 @@
package zaplog
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"gopkg.in/natefinch/lumberjack.v2"
)
type Config struct {
Level zapcore.Level
LogPath string
MaxSizeInMB int
MaxBackups int
Name string
}
const (
maxLogFileSizeInMb = 5
maxLogFileCount = 8
)
var (
loggerName string
loggerFile string
)
var LoggerCfg = Config{
Level: zapcore.DebugLevel,
LogPath: loggerFile,
MaxSizeInMB: maxLogFileSizeInMb,
MaxBackups: maxLogFileCount,
Name: loggerName,
}
func InitZapLog(cfg *Config) *zap.Logger {
logFileWriter := zapcore.AddSync(&lumberjack.Logger{
Filename: cfg.LogPath,
MaxSize: cfg.MaxSizeInMB,
MaxBackups: cfg.MaxBackups,
})
encoderConfig := zap.NewProductionEncoderConfig()
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
jsonEncoder := zapcore.NewJSONEncoder(encoderConfig)
logLevel := cfg.Level
core := zapcore.NewCore(jsonEncoder, logFileWriter, logLevel)
Logger := zap.New(core)
return Logger
}