github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/admin/commands/common/set_golog_level.go (about) 1 package common 2 3 import ( 4 "context" 5 "errors" 6 "fmt" 7 8 golog "github.com/ipfs/go-log/v2" 9 "github.com/rs/zerolog/log" 10 11 "github.com/onflow/flow-go/admin" 12 "github.com/onflow/flow-go/admin/commands" 13 ) 14 15 var _ commands.AdminCommand = (*SetGologLevelCommand)(nil) 16 17 type SetGologLevelCommand struct{} 18 19 func (s *SetGologLevelCommand) Handler(ctx context.Context, req *admin.CommandRequest) (interface{}, error) { 20 level := req.ValidatorData.(golog.LogLevel) 21 golog.SetAllLoggers(level) 22 23 log.Info().Msgf("changed log level to %v", level) 24 return "ok", nil 25 } 26 27 func (s *SetGologLevelCommand) Validator(req *admin.CommandRequest) error { 28 level, ok := req.Data.(string) 29 if !ok { 30 return errors.New("the input must be a string") 31 } 32 logLevel, err := golog.LevelFromString(level) 33 if err != nil { 34 return fmt.Errorf("failed to parse level: %w", err) 35 } 36 req.ValidatorData = logLevel 37 return nil 38 }