-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1362: [Admin] add log level customization command r=smnzhu a=smnzhu Add log level admin command, to allow dynamically changing the log level without restarting a node. Tested and it works on localnet. To change the log level to debug, for example: ``` curl -d '{"commandName": "set-log-level", "data": {"level": "debug"}}' -H 'Content-Type: application/json' localhost:5873/admin/run_command ``` where `localhost:5873` is the address of the admin server. Co-authored-by: Simon Zhu <simon.zsiyan@gmail.com>
- Loading branch information
Showing
8 changed files
with
122 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package commands | ||
|
||
import "github.com/onflow/flow-go/admin" | ||
|
||
type AdminCommand struct { | ||
Handler admin.CommandHandler | ||
Validator admin.CommandValidator | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package common | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/rs/zerolog" | ||
|
||
"github.com/onflow/flow-go/admin" | ||
"github.com/onflow/flow-go/admin/commands" | ||
) | ||
|
||
var SetLogLevelCommand commands.AdminCommand = commands.AdminCommand{ | ||
Handler: func(ctx context.Context, req *admin.CommandRequest) error { | ||
level := req.ValidatorData.(zerolog.Level) | ||
zerolog.SetGlobalLevel(level) | ||
return nil | ||
}, | ||
Validator: func(req *admin.CommandRequest) error { | ||
level, ok := req.Data["level"] | ||
if !ok { | ||
return errors.New("the \"level\" field must be provided") | ||
} | ||
levelStr, ok := level.(string) | ||
if !ok { | ||
return errors.New("\"level\" must be a string") | ||
} | ||
logLevel, err := zerolog.ParseLevel(levelStr) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse level: %w", err) | ||
} | ||
req.ValidatorData = logLevel | ||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters