Enable logging on all subcommands (#4921)

Signed-off-by: Derek Nola <derek.nola@suse.com>
pull/4867/head
Derek Nola 2022-01-12 14:00:40 -08:00 committed by GitHub
parent a0cadcd343
commit 48ffed3852
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 16 deletions

View File

@ -214,7 +214,7 @@ func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
Name: "agent", Name: "agent",
Usage: "Run node agent", Usage: "Run node agent",
UsageText: appName + " agent [OPTIONS]", UsageText: appName + " agent [OPTIONS]",
Before: SetupDebug(CheckSELinuxFlags), Before: CheckSELinuxFlags,
Action: action, Action: action,
Flags: []cli.Flag{ Flags: []cli.Flag{
ConfigFlag, ConfigFlag,

View File

@ -7,6 +7,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/sirupsen/logrus"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -76,4 +77,7 @@ func setupLogging() {
flag.Set("vmodule", LogConfig.VModule) flag.Set("vmodule", LogConfig.VModule)
flag.Set("alsologtostderr", strconv.FormatBool(Debug)) flag.Set("alsologtostderr", strconv.FormatBool(Debug))
flag.Set("logtostderr", strconv.FormatBool(!Debug)) flag.Set("logtostderr", strconv.FormatBool(!Debug))
if Debug {
logrus.SetLevel(logrus.DebugLevel)
}
} }

View File

@ -6,7 +6,6 @@ import (
"runtime" "runtime"
"github.com/rancher/k3s/pkg/version" "github.com/rancher/k3s/pkg/version"
"github.com/sirupsen/logrus"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -43,19 +42,6 @@ func NewApp() *cli.App {
Usage: "(data) Folder to hold state default /var/lib/rancher/" + version.Program + " or ${HOME}/.rancher/" + version.Program + " if not root", Usage: "(data) Folder to hold state default /var/lib/rancher/" + version.Program + " or ${HOME}/.rancher/" + version.Program + " if not root",
}, },
} }
app.Before = SetupDebug(nil)
return app return app
} }
func SetupDebug(next func(ctx *cli.Context) error) func(ctx *cli.Context) error {
return func(ctx *cli.Context) error {
if Debug {
logrus.SetLevel(logrus.DebugLevel)
}
if next != nil {
return next(ctx)
}
return nil
}
}

View File

@ -514,7 +514,7 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command {
Name: "server", Name: "server",
Usage: "Run management server", Usage: "Run management server",
UsageText: appName + " server [OPTIONS]", UsageText: appName + " server [OPTIONS]",
Before: SetupDebug(CheckSELinuxFlags), Before: CheckSELinuxFlags,
Action: action, Action: action,
Flags: ServerFlags, Flags: ServerFlags,
} }