Skip to content

Commit

Permalink
Log error changing default level
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf authored and roboquat committed Sep 22, 2021
1 parent 23efb33 commit f25de2c
Show file tree
Hide file tree
Showing 25 changed files with 68 additions and 36 deletions.
5 changes: 3 additions & 2 deletions components/blobserve/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var rootCmd = &cobra.Command{
Short: "This service provides static assets from OCI images",
Args: cobra.MinimumNArgs(1),
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.Init(ServiceName, Version, jsonLog, jsonLog)
log.Init(ServiceName, Version, jsonLog, verbose)

// configure containerd log with gitpod-io configuration
containerd_log.WithLogger(context.Background(), log.Log)
Expand All @@ -52,7 +52,8 @@ func Execute() {
}

func init() {
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "v", false, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "j", true, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose JSON logging")
}

// Config configures this servuce
Expand Down
1 change: 1 addition & 0 deletions components/blobserve/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
)

var jsonLog bool
var verbose bool

// runCmd represents the run command
var runCmd = &cobra.Command{
Expand Down
11 changes: 7 additions & 4 deletions components/common-go/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ func init() {

func logLevelFromEnv() {
level := os.Getenv("LOG_LEVEL")
if level == "" {
return
if len(level) == 0 {
level = "info"
}

newLevel, err := logrus.ParseLevel(level)
if err == nil {
Log.Logger.SetLevel(newLevel)
if err != nil {
Log.WithError(err).Errorf("cannot change log level to '%v'", level)
return
}

Log.Logger.SetLevel(newLevel)
}

// Init initializes/configures the application-wide logger
Expand Down
5 changes: 4 additions & 1 deletion components/content-service/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ var (
Version = ""
)

var jsonLog bool
var verbose bool
var configFile string

var rootCmd = &cobra.Command{
Use: "content-service",
Short: "Content service",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.Init(ServiceName, Version, verbose, verbose)
log.Init(ServiceName, Version, jsonLog, verbose)
},
}

Expand Down Expand Up @@ -69,6 +71,7 @@ func getConfig() *serviceConfig {
}

func init() {
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "j", true, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose JSON logging")
rootCmd.PersistentFlags().StringVar(&configFile, "config", "", "config file")
}
Expand Down
6 changes: 4 additions & 2 deletions components/ee/agent-smith/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ var (

var cfgFile string
var jsonLog bool
var verbose bool

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "agent-smith",
Short: "Moves through workspace pods and finds bad players",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
os.Args = []string{""}
log.Init(ServiceName, Version, jsonLog, jsonLog)
log.Init(ServiceName, Version, jsonLog, verbose)

// Disable golog, Googles logging framwork for misanthropic
err := goflag.Set("stderrthreshold", "5")
Expand All @@ -56,7 +57,8 @@ func Execute() {

func init() {
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file")
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "v", false, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "j", true, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose JSON logging")
}

func getConfig() (*config, error) {
Expand Down
6 changes: 4 additions & 2 deletions components/ee/kedge/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ var (

var cfgFile string
var jsonLog bool
var verbose bool

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "kedge",
Short: "Remote kubernetes service discovery and replication",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.Init(ServiceName, Version, jsonLog, jsonLog)
log.Init(ServiceName, Version, jsonLog, verbose)
},
}

Expand All @@ -47,8 +48,9 @@ func Execute() {

func init() {
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "confg.json", "config file")
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "v", false, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "j", true, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().String("kubeconfig", "", "kubernetes client config file")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose JSON logging")
}

func getConfig() (*config, error) {
Expand Down
6 changes: 4 additions & 2 deletions components/ee/ws-scheduler/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ var (
var cfgFile string
var kubeconfig string
var jsonLog bool
var verbose bool

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "ws-scheduler",
Short: "ws-scheduler schedules workspace pods to nodes",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.Init(ServiceName, Version, jsonLog, jsonLog)
log.Init(ServiceName, Version, jsonLog, verbose)
},
}

Expand All @@ -57,7 +58,8 @@ func Execute() {

func init() {
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.kedgei.yaml)")
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "v", false, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "j", true, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose JSON logging")

rootCmd.PersistentFlags().StringVar(&kubeconfig, "kubeconfig", "", "path to the kubeconfig file to use (defaults to in-cluster config)")
}
Expand Down
2 changes: 1 addition & 1 deletion components/image-builder-bob/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var rootCmd = &cobra.Command{

// Execute runs the root command
func Execute() {
log.Init("bob", "", false, false)
log.Init("bob", "", true, false)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
4 changes: 3 additions & 1 deletion components/image-builder-mk3/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ var (
Version = ""
)

var jsonLog bool
var verbose bool
var configFile string
var rootCmd = &cobra.Command{
Use: "image-builder-mk3",
Short: "Workspace image-builder service",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.Init(ServiceName, Version, verbose && !isatty.IsTerminal(os.Stdout.Fd()), verbose)
log.Init(ServiceName, Version, jsonLog && !isatty.IsTerminal(os.Stdout.Fd()), verbose)
},
}

Expand Down Expand Up @@ -71,6 +72,7 @@ func getConfig() *config {
}

func init() {
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "j", true, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose JSON logging")
rootCmd.PersistentFlags().StringVar(&configFile, "config", "", "config file")
}
Expand Down
5 changes: 4 additions & 1 deletion components/image-builder/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ var (
Version = ""
)

var jsonLog bool
var verbose bool
var configFile string

var rootCmd = &cobra.Command{
Use: "image-builder",
Short: "Workspace image-builder service",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.Init(ServiceName, Version, verbose && !isatty.IsTerminal(os.Stdout.Fd()), verbose)
log.Init(ServiceName, Version, jsonLog && !isatty.IsTerminal(os.Stdout.Fd()), verbose)
},
}

Expand Down Expand Up @@ -70,6 +72,7 @@ func getConfig() *config {
}

func init() {
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "j", true, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose JSON logging")
rootCmd.PersistentFlags().StringVar(&configFile, "config", "", "config file")
}
Expand Down
5 changes: 3 additions & 2 deletions components/registry-facade/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var rootCmd = &cobra.Command{
Short: "This service acts as image registry augmenting images with workspace content and Theia",
Args: cobra.MinimumNArgs(1),
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.Init(ServiceName, Version, jsonLog, jsonLog)
log.Init(ServiceName, Version, jsonLog, verbose)
},
}

Expand All @@ -47,7 +47,8 @@ func Execute() {
}

func init() {
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "v", false, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "j", true, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose JSON logging")
}

// Config configures this servuce
Expand Down
1 change: 1 addition & 0 deletions components/registry-facade/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
)

var jsonLog bool
var verbose bool

// runCmd represents the run command
var runCmd = &cobra.Command{
Expand Down
6 changes: 4 additions & 2 deletions components/service-waiter/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ var (

var cfgFile string
var jsonLog bool
var verbose bool

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "service-waiter",
Short: "service-waiter waits until a service becomes available",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.Init(ServiceName, Version, jsonLog, jsonLog)
log.Init(ServiceName, Version, jsonLog, verbose)
},
}

Expand All @@ -48,7 +49,8 @@ func init() {
cobra.OnInitialize(initConfig)

rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.service-waiter.yaml)")
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "v", false, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "j", true, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose JSON logging")

defaultTimeout := os.Getenv("SERVICE_WAITER_TIMEOUT")
if defaultTimeout == "" {
Expand Down
2 changes: 1 addition & 1 deletion components/supervisor/cmd/ghost.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var ghostCmd = &cobra.Command{
Short: "starts the supervisor",

Run: func(cmd *cobra.Command, args []string) {
log.Init(ServiceName, Version, true, true)
log.Init(ServiceName, Version, true, false)
log.Info("running as ghost - waiting for SIGTERM")

sigChan := make(chan os.Signal, 1)
Expand Down
2 changes: 1 addition & 1 deletion components/supervisor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
log.Init(ServiceName, Version, false, true)
log.Init(ServiceName, Version, true, false)
log.Log.Logger.AddHook(fatalTerminationLogHook{})

if err := rootCmd.Execute(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion components/supervisor/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var runCmd = &cobra.Command{
Short: "starts the supervisor",

Run: func(cmd *cobra.Command, args []string) {
log.Init(ServiceName, Version, true, true)
log.Init(ServiceName, Version, true, false)
common_grpc.SetupLogging()
supervisor.Run()
},
Expand Down
6 changes: 3 additions & 3 deletions components/workspacekit/cmd/rings.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var ring0Cmd = &cobra.Command{
Use: "ring0",
Short: "starts ring0 - enter here",
Run: func(_ *cobra.Command, args []string) {
log.Init(ServiceName, Version, true, true)
log.Init(ServiceName, Version, true, false)
log := log.WithField("ring", 0)

common_grpc.SetupLogging()
Expand Down Expand Up @@ -183,7 +183,7 @@ var ring1Cmd = &cobra.Command{
Use: "ring1",
Short: "starts ring1",
Run: func(_cmd *cobra.Command, args []string) {
log.Init(ServiceName, Version, true, true)
log.Init(ServiceName, Version, true, false)
log := log.WithField("ring", 1)

common_grpc.SetupLogging()
Expand Down Expand Up @@ -614,7 +614,7 @@ var ring2Cmd = &cobra.Command{
Short: "starts ring2",
Args: cobra.ExactArgs(1),
Run: func(_cmd *cobra.Command, args []string) {
log.Init(ServiceName, Version, true, true)
log.Init(ServiceName, Version, true, false)
log := log.WithField("ring", 2)

common_grpc.SetupLogging()
Expand Down
2 changes: 1 addition & 1 deletion components/workspacekit/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
log.Init(ServiceName, Version, false, true)
log.Init(ServiceName, Version, true, false)

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
Expand Down
2 changes: 1 addition & 1 deletion components/ws-daemon/cmd/content-initializer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func main() {
log.Init("content-initializer", "", true, true)
log.Init("content-initializer", "", true, false)
tracing.Init("content-initializer")

err := content.RunInitializerChild()
Expand Down
5 changes: 4 additions & 1 deletion components/ws-daemon/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ var (

var verbose bool
var configFile string
var jsonLog bool

var rootCmd = &cobra.Command{
Use: "ws-daemond",
Short: "Workspace initialization and synchronization daemon",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.Init(ServiceName, Version, verbose, verbose)
log.Init(ServiceName, Version, jsonLog, verbose)
},
}

Expand Down Expand Up @@ -70,6 +72,7 @@ func getConfig() *config {
}

func init() {
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "j", true, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose JSON logging")
rootCmd.PersistentFlags().StringVar(&configFile, "config", "", "config file")
}
Expand Down
2 changes: 1 addition & 1 deletion components/ws-daemon/nsinsider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func main() {
},
}

log.Init("nsinsider", "", true, true)
log.Init("nsinsider", "", true, false)
err := app.Run(os.Args)
if err != nil {
log.WithField("instanceId", os.Getenv("GITPOD_INSTANCE_ID")).WithField("args", os.Args).Fatal(err)
Expand Down
6 changes: 4 additions & 2 deletions components/ws-manager/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ var (
var cfgFile string
var kubeconfig string
var jsonLog bool
var verbose bool

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "ws-manager",
Short: "ws-manager starts/stops/controls workspace deployments in Kubernetes",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.Init(ServiceName, Version, jsonLog, jsonLog)
log.Init(ServiceName, Version, jsonLog, verbose)
},
}

Expand Down Expand Up @@ -65,7 +66,8 @@ func Execute() {

func init() {
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.kedgei.yaml)")
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "v", false, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "j", true, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose JSON logging")

rootCmd.PersistentFlags().StringVar(&kubeconfig, "kubeconfig", "", "path to the kubeconfig file to use (defaults to in-cluster config)")
}
Expand Down
Loading

0 comments on commit f25de2c

Please sign in to comment.