2023-08-10 09:06:00 +00:00
|
|
|
// Copyright 2023 Woodpecker Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
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
|
|
|
|
}
|