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:
parent
a03121eb60
commit
595b78f487
4 changed files with 27 additions and 16 deletions
|
@ -3,6 +3,7 @@
|
|||
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
|
||||
- Add v2alpha1 API for ArangoDeployment and ArangoDeploymentReplication
|
||||
- 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)
|
||||
- Fix Bootstrap phase and move it under Plan
|
||||
|
|
6
main.go
6
main.go
|
@ -92,7 +92,7 @@ var (
|
|||
Run: cmdMainRun,
|
||||
}
|
||||
|
||||
logLevel string
|
||||
logLevels []string
|
||||
cliLog = logging.NewRootLogger()
|
||||
logService logging.Service
|
||||
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.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.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.enableDeploymentReplication, "operator.deployment-replication", false, "Enable to run the ArangoDeploymentReplication 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
|
||||
var err error
|
||||
logService, err = logging.NewService(logLevel)
|
||||
logService, err = logging.NewService(defaultLogLevel, logLevels)
|
||||
if err != nil {
|
||||
cliLog.Fatal().Err(err).Msg("Failed to initialize log service")
|
||||
}
|
||||
|
|
|
@ -29,16 +29,9 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
"github.com/pkg/errors"
|
||||
|
||||
var (
|
||||
// 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",
|
||||
}
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
// Service exposes the interfaces for a logger service
|
||||
|
@ -70,7 +63,7 @@ func NewRootLogger() zerolog.Logger {
|
|||
}
|
||||
|
||||
// NewService creates a new Service.
|
||||
func NewService(defaultLevel string) (Service, error) {
|
||||
func NewService(defaultLevel string, overrides []string) (Service, error) {
|
||||
l, err := stringToLevel(defaultLevel)
|
||||
if err != nil {
|
||||
return nil, maskAny(err)
|
||||
|
@ -81,8 +74,25 @@ func NewService(defaultLevel string) (Service, error) {
|
|||
defaultLevel: l,
|
||||
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
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ func init() {
|
|||
func cmdStorageProvisionerRun(cmd *cobra.Command, args []string) {
|
||||
//goflag.CommandLine.Parse([]string{"-logtostderr"})
|
||||
var err error
|
||||
logService, err = logging.NewService(logLevel)
|
||||
logService, err = logging.NewService(defaultLogLevel, logLevels)
|
||||
if err != nil {
|
||||
cliLog.Fatal().Err(err).Msg("Failed to initialize log service")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue