-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add log level and flag operations (#76)
* Add log level and flag operations Longhorn 7939 Signed-off-by: Derek Su <[email protected]> --------- Signed-off-by: Derek Su <[email protected]> Signed-off-by: David Ko <[email protected]> Co-authored-by: David Ko <[email protected]> Co-authored-by: David Ko <[email protected]>
- Loading branch information
1 parent
b64c3bc
commit a6d23f9
Showing
5 changed files
with
338 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
package basic | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/urfave/cli" | ||
|
||
"github.com/longhorn/go-spdk-helper/pkg/spdk/client" | ||
"github.com/longhorn/go-spdk-helper/pkg/util" | ||
) | ||
|
||
func LogCmd() cli.Command { | ||
return cli.Command{ | ||
Name: "log", | ||
Subcommands: []cli.Command{ | ||
LogSetFlagCmd(), | ||
LogClearFlagCmd(), | ||
LogGetFlagsCmd(), | ||
LogSetLevelCmd(), | ||
LogGetLevelCmd(), | ||
LogSetPrintLevelCmd(), | ||
LogGetPrintLevelCmd(), | ||
}, | ||
} | ||
} | ||
|
||
func LogSetFlagCmd() cli.Command { | ||
return cli.Command{ | ||
Name: "set-flag", | ||
Usage: "set log flag: set-flag <FLAG>", | ||
Action: func(c *cli.Context) { | ||
if err := logSetFlag(c); err != nil { | ||
logrus.WithError(err).Fatalf("Failed to run set log flag command") | ||
} | ||
}, | ||
} | ||
} | ||
|
||
func logSetFlag(c *cli.Context) error { | ||
spdkCli, err := client.NewClient(context.Background()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
result, err := spdkCli.LogSetFlag(c.Args().First()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return util.PrintObject(result) | ||
} | ||
|
||
func LogClearFlagCmd() cli.Command { | ||
return cli.Command{ | ||
Name: "clear-flag", | ||
Usage: "clear log flag: clear-flag <FLAG>", | ||
Action: func(c *cli.Context) { | ||
if err := logClearFlag(c); err != nil { | ||
logrus.WithError(err).Fatalf("Failed to run clear log flag command") | ||
} | ||
}, | ||
} | ||
} | ||
|
||
func logClearFlag(c *cli.Context) error { | ||
spdkCli, err := client.NewClient(context.Background()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
result, err := spdkCli.LogClearFlag(c.Args().First()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return util.PrintObject(result) | ||
} | ||
|
||
func LogGetFlagsCmd() cli.Command { | ||
return cli.Command{ | ||
Name: "get-flags", | ||
Usage: "get log flags", | ||
Action: func(c *cli.Context) { | ||
if err := logGetFlags(c); err != nil { | ||
logrus.WithError(err).Fatalf("Failed to run get log flags command") | ||
} | ||
}, | ||
} | ||
} | ||
|
||
func logGetFlags(c *cli.Context) error { | ||
spdkCli, err := client.NewClient(context.Background()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
logFlags, err := spdkCli.LogGetFlags() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return util.PrintObject(logFlags) | ||
} | ||
|
||
func LogSetLevelCmd() cli.Command { | ||
return cli.Command{ | ||
Name: "set-level", | ||
Usage: "set log level: set-level <LEVEL>", | ||
Action: func(c *cli.Context) { | ||
if err := logSetLevel(c); err != nil { | ||
logrus.WithError(err).Fatalf("Failed to run set log level command") | ||
} | ||
}, | ||
} | ||
} | ||
|
||
func logSetLevel(c *cli.Context) error { | ||
spdkCli, err := client.NewClient(context.Background()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
result, err := spdkCli.LogSetLevel(c.Args().First()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return util.PrintObject(result) | ||
} | ||
|
||
func LogGetLevelCmd() cli.Command { | ||
return cli.Command{ | ||
Name: "get-level", | ||
Usage: "get log level", | ||
Action: func(c *cli.Context) { | ||
if err := logGetLevel(c); err != nil { | ||
logrus.WithError(err).Fatalf("Failed to run get log level command") | ||
} | ||
}, | ||
} | ||
} | ||
|
||
func logGetLevel(c *cli.Context) error { | ||
spdkCli, err := client.NewClient(context.Background()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
logLevel, err := spdkCli.LogGetLevel() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return util.PrintObject(logLevel) | ||
} | ||
|
||
func LogSetPrintLevelCmd() cli.Command { | ||
return cli.Command{ | ||
Name: "set-print-level", | ||
Usage: "set log print level: set-print-level <LEVEL>", | ||
Action: func(c *cli.Context) { | ||
if err := logSetPrintLevel(c); err != nil { | ||
logrus.WithError(err).Fatalf("Failed to run set log print level command") | ||
} | ||
}, | ||
} | ||
} | ||
|
||
func logSetPrintLevel(c *cli.Context) error { | ||
spdkCli, err := client.NewClient(context.Background()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
result, err := spdkCli.LogSetPrintLevel(c.Args().First()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return util.PrintObject(result) | ||
} | ||
|
||
func LogGetPrintLevelCmd() cli.Command { | ||
return cli.Command{ | ||
Name: "get-print-level", | ||
Usage: "get log print level", | ||
Action: func(c *cli.Context) { | ||
if err := logGetPrintLevel(c); err != nil { | ||
logrus.WithError(err).Fatalf("Failed to run get log print level command") | ||
} | ||
}, | ||
} | ||
} | ||
|
||
func logGetPrintLevel(c *cli.Context) error { | ||
spdkCli, err := client.NewClient(context.Background()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
logPrintLevel, err := spdkCli.LogGetPrintLevel() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return util.PrintObject(logPrintLevel) | ||
} |
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,26 @@ | ||
package types | ||
|
||
type LogSetFlagRequest struct { | ||
Flag string `json:"flag"` | ||
} | ||
|
||
type LogClearFlagRequest struct { | ||
Flag string `json:"flag"` | ||
} | ||
|
||
type LogGetFlagsRequest struct { | ||
} | ||
|
||
type LogSetLevelRequest struct { | ||
Level string `json:"level"` | ||
} | ||
|
||
type LogGetLevelRequest struct { | ||
} | ||
|
||
type LogSetPrintLevelRequest struct { | ||
Level string `json:"level"` | ||
} | ||
|
||
type LogGetPrintLevelRequest struct { | ||
} |