1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Feature] Enable logger overrides (#672)

This commit is contained in:
Adam Janikowski 2020-11-23 08:58:40 +01:00 committed by GitHub
parent a03121eb60
commit 595b78f487
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 16 deletions

View file

@ -3,6 +3,7 @@
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A) ## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
- Add v2alpha1 API for ArangoDeployment and ArangoDeploymentReplication - Add v2alpha1 API for ArangoDeployment and ArangoDeploymentReplication
- Migrate CRD to apiextensions.k8s.io/v1 - Migrate CRD to apiextensions.k8s.io/v1
- Add customizable log levels per service
## [1.1.2](https://github.com/arangodb/kube-arangodb/tree/1.1.2) (2020-11-11) ## [1.1.2](https://github.com/arangodb/kube-arangodb/tree/1.1.2) (2020-11-11)
- Fix Bootstrap phase and move it under Plan - Fix Bootstrap phase and move it under Plan

View file

@ -92,7 +92,7 @@ var (
Run: cmdMainRun, Run: cmdMainRun,
} }
logLevel string logLevels []string
cliLog = logging.NewRootLogger() cliLog = logging.NewRootLogger()
logService logging.Service logService logging.Service
serverOptions struct { serverOptions struct {
@ -131,7 +131,7 @@ func init() {
f.StringVar(&serverOptions.tlsSecretName, "server.tls-secret-name", "", "Name of secret containing tls.crt & tls.key for HTTPS server (if empty, self-signed certificate is used)") f.StringVar(&serverOptions.tlsSecretName, "server.tls-secret-name", "", "Name of secret containing tls.crt & tls.key for HTTPS server (if empty, self-signed certificate is used)")
f.StringVar(&serverOptions.adminSecretName, "server.admin-secret-name", defaultAdminSecretName, "Name of secret containing username + password for login to the dashboard") f.StringVar(&serverOptions.adminSecretName, "server.admin-secret-name", defaultAdminSecretName, "Name of secret containing username + password for login to the dashboard")
f.BoolVar(&serverOptions.allowAnonymous, "server.allow-anonymous-access", false, "Allow anonymous access to the dashboard") f.BoolVar(&serverOptions.allowAnonymous, "server.allow-anonymous-access", false, "Allow anonymous access to the dashboard")
f.StringVar(&logLevel, "log.level", defaultLogLevel, "Set initial log level") f.StringArrayVar(&logLevels, "log.level", []string{defaultLogLevel}, "Set log levels in format <level> or <logger>=<level>")
f.BoolVar(&operatorOptions.enableDeployment, "operator.deployment", false, "Enable to run the ArangoDeployment operator") f.BoolVar(&operatorOptions.enableDeployment, "operator.deployment", false, "Enable to run the ArangoDeployment operator")
f.BoolVar(&operatorOptions.enableDeploymentReplication, "operator.deployment-replication", false, "Enable to run the ArangoDeploymentReplication operator") f.BoolVar(&operatorOptions.enableDeploymentReplication, "operator.deployment-replication", false, "Enable to run the ArangoDeploymentReplication operator")
f.BoolVar(&operatorOptions.enableStorage, "operator.storage", false, "Enable to run the ArangoLocalStorage operator") f.BoolVar(&operatorOptions.enableStorage, "operator.storage", false, "Enable to run the ArangoLocalStorage operator")
@ -170,7 +170,7 @@ func cmdMainRun(cmd *cobra.Command, args []string) {
// Prepare log service // Prepare log service
var err error var err error
logService, err = logging.NewService(logLevel) logService, err = logging.NewService(defaultLogLevel, logLevels)
if err != nil { if err != nil {
cliLog.Fatal().Err(err).Msg("Failed to initialize log service") cliLog.Fatal().Err(err).Msg("Failed to initialize log service")
} }

View file

@ -29,16 +29,9 @@ import (
"sync" "sync"
"time" "time"
"github.com/rs/zerolog" "github.com/pkg/errors"
)
var ( "github.com/rs/zerolog"
// The defaultLevels list is used during development to increase the
// default level for components that we care a little less about.
defaultLevels = map[string]string{
//"operator": "info",
//"something.status": "info",
}
) )
// Service exposes the interfaces for a logger service // Service exposes the interfaces for a logger service
@ -70,7 +63,7 @@ func NewRootLogger() zerolog.Logger {
} }
// NewService creates a new Service. // NewService creates a new Service.
func NewService(defaultLevel string) (Service, error) { func NewService(defaultLevel string, overrides []string) (Service, error) {
l, err := stringToLevel(defaultLevel) l, err := stringToLevel(defaultLevel)
if err != nil { if err != nil {
return nil, maskAny(err) return nil, maskAny(err)
@ -81,8 +74,25 @@ func NewService(defaultLevel string) (Service, error) {
defaultLevel: l, defaultLevel: l,
levels: make(map[string]zerolog.Level), levels: make(map[string]zerolog.Level),
} }
for k, v := range defaultLevels {
s.MustSetLevel(k, v) for _, override := range overrides {
levelParts := strings.Split(override, "=")
switch size := len(levelParts); size {
case 1:
level, err := stringToLevel(levelParts[0])
if err != nil {
return nil, maskAny(err)
}
s.defaultLevel = level
case 2:
level, err := stringToLevel(levelParts[1])
if err != nil {
return nil, maskAny(err)
}
s.levels[levelParts[0]] = level
default:
return nil, errors.Errorf("invalid log definition %s: Length %d is not equal 1 or 2", override, size)
}
} }
return s, nil return s, nil
} }

View file

@ -64,7 +64,7 @@ func init() {
func cmdStorageProvisionerRun(cmd *cobra.Command, args []string) { func cmdStorageProvisionerRun(cmd *cobra.Command, args []string) {
//goflag.CommandLine.Parse([]string{"-logtostderr"}) //goflag.CommandLine.Parse([]string{"-logtostderr"})
var err error var err error
logService, err = logging.NewService(logLevel) logService, err = logging.NewService(defaultLogLevel, logLevels)
if err != nil { if err != nil {
cliLog.Fatal().Err(err).Msg("Failed to initialize log service") cliLog.Fatal().Err(err).Msg("Failed to initialize log service")
} }