Add verbosity flag to all services (#244)

Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
Daniel Weiße 2022-07-01 16:17:06 +02:00 committed by GitHub
parent 3177b2fdb7
commit 0a874496b3
7 changed files with 44 additions and 17 deletions

View File

@ -3,6 +3,7 @@ package main
import (
"context"
"errors"
"flag"
"fmt"
"os"
"path"
@ -15,7 +16,6 @@ import (
"github.com/edgelesssys/constellation/internal/logger"
"github.com/spf13/afero"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
v1 "k8s.io/api/core/v1"
v1Options "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -48,7 +48,10 @@ type uidGIDPair struct {
}
func main() {
log := logger.New(logger.JSONLog, zapcore.InfoLevel)
verbosity := flag.Int("v", 0, logger.CmdLineVerbosityDescription)
flag.Parse()
log := logger.New(logger.JSONLog, logger.VerbosityFromInt(*verbosity))
hostname, err := os.Hostname()
if err != nil {

View File

@ -17,16 +17,15 @@ import (
"github.com/edgelesssys/constellation/internal/watcher"
"github.com/spf13/afero"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func main() {
provider := flag.String("cloud-provider", "", "cloud service provider this binary is running on")
kmsEndpoint := flag.String("kms-endpoint", "", "endpoint of Constellations key management service")
verbosity := flag.Int("v", 0, "log verbosity in zap logging levels. Use -1 for debug information, 0 for info, 1 for warn, 2 for error")
verbosity := flag.Int("v", 0, logger.CmdLineVerbosityDescription)
flag.Parse()
log := logger.New(logger.JSONLog, zapcore.Level(*verbosity))
log := logger.New(logger.JSONLog, logger.VerbosityFromInt(*verbosity))
log.With(zap.String("version", constants.VersionInfo), zap.String("cloudProvider", *provider)).
Infof("Constellation Node Activation Service")

View File

@ -1,6 +1,7 @@
package main
import (
"flag"
"net"
"os"
"sync"
@ -16,14 +17,15 @@ import (
"github.com/edgelesssys/constellation/internal/deploy/user"
"github.com/edgelesssys/constellation/internal/logger"
"github.com/spf13/afero"
"go.uber.org/zap/zapcore"
"golang.org/x/net/context"
)
func main() {
wg := &sync.WaitGroup{}
verbosity := flag.Int("v", 0, logger.CmdLineVerbosityDescription)
log := logger.New(logger.JSONLog, zapcore.InfoLevel)
flag.Parse()
log := logger.New(logger.JSONLog, logger.VerbosityFromInt(*verbosity))
fs := afero.NewOsFs()
streamer := coordinator.NewFileStreamer(fs)
serviceManager := deploy.NewServiceManager(log.Named("serviceManager"))

View File

@ -0,0 +1,24 @@
package logger
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
const CmdLineVerbosityDescription = "log verbosity in zap logging levels. Use -1 for debug information, 0 for info, 1 for warn, 2 for error"
// VerbosityFromInt converts a verbosity level from an integer to a zapcore.Level.
func VerbosityFromInt(verbosity int) zapcore.Level {
switch {
case verbosity <= -1:
return zap.DebugLevel
case verbosity == 0:
return zap.InfoLevel
case verbosity == 1:
return zap.WarnLevel
case verbosity >= 2:
return zap.ErrorLevel
default:
return zap.InfoLevel
}
}

View File

@ -20,7 +20,6 @@ import (
"github.com/edgelesssys/constellation/kms/setup"
"github.com/spf13/afero"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func main() {
@ -28,9 +27,10 @@ func main() {
portATLS := flag.String("atls-port", strconv.Itoa(constants.KMSNodePort), "Port aTLS server listens on")
provider := flag.String("cloud-provider", "", "cloud service provider this binary is running on")
masterSecretPath := flag.String("master-secret", filepath.Join(constants.ServiceBasePath, constants.MasterSecretFilename), "Path to the Constellation master secret")
verbosity := flag.Int("v", 0, logger.CmdLineVerbosityDescription)
flag.Parse()
log := logger.New(logger.JSONLog, zapcore.InfoLevel)
log := logger.New(logger.JSONLog, logger.VerbosityFromInt(*verbosity))
log.With(zap.String("version", constants.VersionInfo), zap.String("cloudProvider", *provider)).
Infof("Constellation Key Management Service")

View File

@ -23,7 +23,6 @@ import (
"github.com/edgelesssys/constellation/state/setup"
"github.com/spf13/afero"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
const (
@ -32,12 +31,12 @@ const (
qemuStateDiskPath = "/dev/vda"
)
var csp = flag.String("csp", "", "Cloud Service Provider the image is running on")
func main() {
flag.Parse()
csp := flag.String("csp", "", "Cloud Service Provider the image is running on")
verbosity := flag.Int("v", 0, logger.CmdLineVerbosityDescription)
log := logger.New(logger.JSONLog, zapcore.InfoLevel)
flag.Parse()
log := logger.New(logger.JSONLog, logger.VerbosityFromInt(*verbosity))
log.With(zap.String("version", constants.VersionInfo), zap.String("cloudProvider", *csp)).
Infof("Starting disk-mapper")

View File

@ -12,14 +12,14 @@ import (
"github.com/edgelesssys/constellation/internal/logger"
"github.com/edgelesssys/constellation/verify/server"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func main() {
provider := flag.String("cloud-provider", "", "cloud service provider this binary is running on")
flag.Parse()
verbosity := flag.Int("v", 0, logger.CmdLineVerbosityDescription)
log := logger.New(logger.JSONLog, zapcore.InfoLevel)
flag.Parse()
log := logger.New(logger.JSONLog, logger.VerbosityFromInt(*verbosity))
log.With(zap.String("version", constants.VersionInfo), zap.String("cloudProvider", *provider)).
Infof("Constellation Verification Service")