-
Notifications
You must be signed in to change notification settings - Fork 924
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cmd/node): add logs cmd to dynamically change the log level (#2601)
## Overview Added cmds that allow to change log level during runtime ## Checklist <!-- Please complete the checklist to ensure that the PR is ready to be reviewed. IMPORTANT: PRs should be left in Draft until the below checklist is completed. --> - [ ] New and updated code has appropriate documentation - [ ] New and updated code has new and/or updated testing - [ ] Required CI checks are passing - [ ] Visual proof for any user facing features like CLI or documentation updates - [ ] Linked issues closed with keywords
- Loading branch information
Showing
3 changed files
with
57 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/celestiaorg/celestia-node/cmd" | ||
) | ||
|
||
var logCmd = &cobra.Command{ | ||
Use: cmd.LogLevelFlag, | ||
Args: cobra.ExactArgs(1), | ||
Short: "Allows to set log level for all modules to " + | ||
"`DEBUG, INFO, WARN, ERROR, DPANIC, PANIC, FATAL and their lower-case forms`", | ||
|
||
RunE: func(c *cobra.Command, args []string) error { | ||
client, err := rpcClient(c.Context()) | ||
if err != nil { | ||
return err | ||
} | ||
return client.Node.LogLevelSet(c.Context(), "*", args[0]) | ||
}, | ||
} | ||
|
||
var logModuleCmd = &cobra.Command{ | ||
Use: cmd.LogLevelModuleFlag, | ||
Args: cobra.MinimumNArgs(1), | ||
Short: "Allows to set log level for a particular module in format <module>:<level>", | ||
RunE: func(c *cobra.Command, args []string) error { | ||
client, err := rpcClient(c.Context()) | ||
if err != nil { | ||
return err | ||
} | ||
for _, ll := range args { | ||
params := strings.Split(ll, ":") | ||
if len(params) != 2 { | ||
return fmt.Errorf("cmd: %s arg must be in form <module>:<level>,"+ | ||
"e.g. pubsub:debug", cmd.LogLevelModuleFlag) | ||
} | ||
if err = client.Node.LogLevelSet(c.Context(), params[0], params[1]); err != nil { | ||
return err | ||
} | ||
} | ||
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