2021-10-18 23:25:20 +00:00
|
|
|
package loglevel
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
"github.com/rs/zerolog/log"
|
2021-10-27 19:03:14 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2021-10-18 23:25:20 +00:00
|
|
|
|
2021-10-27 19:03:14 +00:00
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/common"
|
2021-10-18 23:25:20 +00:00
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/internal"
|
|
|
|
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Command exports the log-level command used to change the servers log-level.
|
2021-10-27 19:03:14 +00:00
|
|
|
var Command = &cli.Command{
|
2021-10-18 23:25:20 +00:00
|
|
|
Name: "log-level",
|
|
|
|
ArgsUsage: "[level]",
|
|
|
|
Usage: "get the logging level of the server, or set it with [level]",
|
|
|
|
Action: logLevel,
|
2021-10-27 19:03:14 +00:00
|
|
|
Flags: common.GlobalFlags,
|
2021-10-18 23:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func logLevel(c *cli.Context) error {
|
|
|
|
client, err := internal.NewClient(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var ll *woodpecker.LogLevel
|
|
|
|
arg := c.Args().First()
|
|
|
|
if arg != "" {
|
|
|
|
lvl, err := zerolog.ParseLevel(arg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
ll, err = client.SetLogLevel(&woodpecker.LogLevel{
|
|
|
|
Level: lvl.String(),
|
|
|
|
})
|
2021-11-25 16:15:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-10-18 23:25:20 +00:00
|
|
|
} else {
|
|
|
|
ll, err = client.LogLevel()
|
2021-11-25 16:15:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-10-18 23:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Info().Msgf("Logging level: %s", ll.Level)
|
|
|
|
return nil
|
|
|
|
}
|