server: add support for log rotation
Signed-off-by: Sam Batschelet <sbatsche@redhat.com>
This commit is contained in:
@ -68,6 +68,15 @@ const (
|
||||
StdErrLogOutput = "stderr"
|
||||
StdOutLogOutput = "stdout"
|
||||
|
||||
// DefaultLogRotationConfig is the default configuration used for log rotation.
|
||||
// Log rotation is disabled by default.
|
||||
// MaxSize = 100 // MB
|
||||
// MaxAge = 0 // days (no limit)
|
||||
// MaxBackups = 0 // no limit
|
||||
// LocalTime = false // use computers local time, UTC by default
|
||||
// Compress = false // compress the rotated log in gzip format
|
||||
DefaultLogRotationConfig = `{"maxsize": 100, "maxage": 0, "maxbackups": 0, "localtime": false, "compress": false}`
|
||||
|
||||
// DefaultStrictReconfigCheck is the default value for "--strict-reconfig-check" flag.
|
||||
// It's enabled by default.
|
||||
DefaultStrictReconfigCheck = true
|
||||
@ -86,6 +95,7 @@ var (
|
||||
ErrConflictBootstrapFlags = fmt.Errorf("multiple discovery or bootstrap flags are set. " +
|
||||
"Choose one of \"initial-cluster\", \"discovery\" or \"discovery-srv\"")
|
||||
ErrUnsetAdvertiseClientURLsFlag = fmt.Errorf("--advertise-client-urls is required when --listen-client-urls is set explicitly")
|
||||
ErrLogRotationInvalidLogOutput = fmt.Errorf("--log-outputs requires a single file path when --log-rotate-config-json is defined")
|
||||
|
||||
DefaultInitialAdvertisePeerURLs = "http://localhost:2380"
|
||||
DefaultAdvertiseClientURLs = "http://localhost:2379"
|
||||
@ -320,7 +330,10 @@ type Config struct {
|
||||
// - file path to append server logs to.
|
||||
// It can be multiple when "Logger" is zap.
|
||||
LogOutputs []string `json:"log-outputs"`
|
||||
|
||||
// EnableLogRotation enables log rotation of a single LogOutputs file target.
|
||||
EnableLogRotation bool `json:"enable-log-rotation"`
|
||||
// LogRotationConfigJSON is a passthrough allowing a log rotation JSON config to be passed directly.
|
||||
LogRotationConfigJSON string `json:"log-rotation-config-json"`
|
||||
// ZapLoggerBuilder is used to build the zap logger.
|
||||
ZapLoggerBuilder func(*Config) error
|
||||
|
||||
@ -437,12 +450,14 @@ func NewConfig() *Config {
|
||||
|
||||
PreVote: true,
|
||||
|
||||
loggerMu: new(sync.RWMutex),
|
||||
logger: nil,
|
||||
Logger: "zap",
|
||||
LogOutputs: []string{DefaultLogOutput},
|
||||
LogLevel: logutil.DefaultLogLevel,
|
||||
EnableGRPCGateway: true,
|
||||
loggerMu: new(sync.RWMutex),
|
||||
logger: nil,
|
||||
Logger: "zap",
|
||||
LogOutputs: []string{DefaultLogOutput},
|
||||
LogLevel: logutil.DefaultLogLevel,
|
||||
EnableLogRotation: false,
|
||||
LogRotationConfigJSON: DefaultLogRotationConfig,
|
||||
EnableGRPCGateway: true,
|
||||
|
||||
ExperimentalDowngradeCheckTime: DefaultDowngradeCheckTime,
|
||||
ExperimentalMemoryMlock: false,
|
||||
|
Reference in New Issue
Block a user