Move debug functions to cli/debug package
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
8c1ac81665
commit
ce37550347
7 changed files with 31 additions and 31 deletions
|
@ -12,8 +12,8 @@ import (
|
|||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/cli/command"
|
||||
"github.com/docker/docker/cli/debug"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
"github.com/docker/docker/utils"
|
||||
"github.com/docker/docker/utils/templates"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -206,7 +206,7 @@ func prettyPrintInfo(dockerCli *command.DockerCli, info types.Info) error {
|
|||
ioutils.FprintfIfNotEmpty(dockerCli.Out(), "Name: %s\n", info.Name)
|
||||
ioutils.FprintfIfNotEmpty(dockerCli.Out(), "ID: %s\n", info.ID)
|
||||
fmt.Fprintf(dockerCli.Out(), "Docker Root Dir: %s\n", info.DockerRootDir)
|
||||
fmt.Fprintf(dockerCli.Out(), "Debug Mode (client): %v\n", utils.IsDebugEnabled())
|
||||
fmt.Fprintf(dockerCli.Out(), "Debug Mode (client): %v\n", debug.IsEnabled())
|
||||
fmt.Fprintf(dockerCli.Out(), "Debug Mode (server): %v\n", info.Debug)
|
||||
|
||||
if info.Debug {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package utils
|
||||
package debug
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
@ -6,21 +6,21 @@ import (
|
|||
"github.com/Sirupsen/logrus"
|
||||
)
|
||||
|
||||
// EnableDebug sets the DEBUG env var to true
|
||||
// Enable sets the DEBUG env var to true
|
||||
// and makes the logger to log at debug level.
|
||||
func EnableDebug() {
|
||||
func Enable() {
|
||||
os.Setenv("DEBUG", "1")
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
}
|
||||
|
||||
// DisableDebug sets the DEBUG env var to false
|
||||
// Disable sets the DEBUG env var to false
|
||||
// and makes the logger to log at info level.
|
||||
func DisableDebug() {
|
||||
func Disable() {
|
||||
os.Setenv("DEBUG", "")
|
||||
logrus.SetLevel(logrus.InfoLevel)
|
||||
}
|
||||
|
||||
// IsDebugEnabled checks whether the debug flag is set or not.
|
||||
func IsDebugEnabled() bool {
|
||||
// IsEnabled checks whether the debug flag is set or not.
|
||||
func IsEnabled() bool {
|
||||
return os.Getenv("DEBUG") != ""
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package utils
|
||||
package debug
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
@ -7,12 +7,12 @@ import (
|
|||
"github.com/Sirupsen/logrus"
|
||||
)
|
||||
|
||||
func TestEnableDebug(t *testing.T) {
|
||||
func TestEnable(t *testing.T) {
|
||||
defer func() {
|
||||
os.Setenv("DEBUG", "")
|
||||
logrus.SetLevel(logrus.InfoLevel)
|
||||
}()
|
||||
EnableDebug()
|
||||
Enable()
|
||||
if os.Getenv("DEBUG") != "1" {
|
||||
t.Fatalf("expected DEBUG=1, got %s\n", os.Getenv("DEBUG"))
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ func TestEnableDebug(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDisableDebug(t *testing.T) {
|
||||
DisableDebug()
|
||||
func TestDisable(t *testing.T) {
|
||||
Disable()
|
||||
if os.Getenv("DEBUG") != "" {
|
||||
t.Fatalf("expected DEBUG=\"\", got %s\n", os.Getenv("DEBUG"))
|
||||
}
|
||||
|
@ -31,13 +31,13 @@ func TestDisableDebug(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDebugEnabled(t *testing.T) {
|
||||
EnableDebug()
|
||||
if !IsDebugEnabled() {
|
||||
func TestEnabled(t *testing.T) {
|
||||
Enable()
|
||||
if !IsEnabled() {
|
||||
t.Fatal("expected debug enabled, got false")
|
||||
}
|
||||
DisableDebug()
|
||||
if IsDebugEnabled() {
|
||||
Disable()
|
||||
if IsEnabled() {
|
||||
t.Fatal("expected debug disabled, got true")
|
||||
}
|
||||
}
|
|
@ -10,11 +10,11 @@ import (
|
|||
"github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/cli/command"
|
||||
"github.com/docker/docker/cli/command/commands"
|
||||
"github.com/docker/docker/cli/debug"
|
||||
cliflags "github.com/docker/docker/cli/flags"
|
||||
"github.com/docker/docker/cliconfig"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
"github.com/docker/docker/pkg/term"
|
||||
"github.com/docker/docker/utils"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
@ -130,7 +130,7 @@ func dockerPreRun(opts *cliflags.ClientOptions) {
|
|||
}
|
||||
|
||||
if opts.Common.Debug {
|
||||
utils.EnableDebug()
|
||||
debug.Enable()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,12 +7,12 @@ import (
|
|||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/cli/command"
|
||||
"github.com/docker/docker/cli/debug"
|
||||
"github.com/docker/docker/pkg/testutil/assert"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
func TestClientDebugEnabled(t *testing.T) {
|
||||
defer utils.DisableDebug()
|
||||
defer debug.Disable()
|
||||
|
||||
cmd := newDockerCommand(&command.DockerCli{})
|
||||
cmd.Flags().Set("debug", "true")
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
systemrouter "github.com/docker/docker/api/server/router/system"
|
||||
"github.com/docker/docker/api/server/router/volume"
|
||||
"github.com/docker/docker/builder/dockerfile"
|
||||
"github.com/docker/docker/cli/debug"
|
||||
cliflags "github.com/docker/docker/cli/flags"
|
||||
"github.com/docker/docker/cliconfig"
|
||||
"github.com/docker/docker/daemon"
|
||||
|
@ -44,7 +45,6 @@ import (
|
|||
"github.com/docker/docker/plugin"
|
||||
"github.com/docker/docker/registry"
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/docker/docker/utils"
|
||||
"github.com/docker/go-connections/tlsconfig"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
@ -137,7 +137,7 @@ func (cli *DaemonCli) start(opts daemonOptions) (err error) {
|
|||
}
|
||||
|
||||
if cli.Config.Debug {
|
||||
utils.EnableDebug()
|
||||
debug.Enable()
|
||||
}
|
||||
|
||||
if cli.Config.Experimental {
|
||||
|
@ -351,13 +351,13 @@ func (cli *DaemonCli) reloadConfig() {
|
|||
}
|
||||
|
||||
if config.IsValueSet("debug") {
|
||||
debugEnabled := utils.IsDebugEnabled()
|
||||
debugEnabled := debug.IsEnabled()
|
||||
switch {
|
||||
case debugEnabled && !config.Debug: // disable debug
|
||||
utils.DisableDebug()
|
||||
debug.Disable()
|
||||
cli.api.DisableProfiler()
|
||||
case config.Debug && !debugEnabled: // enable debug
|
||||
utils.EnableDebug()
|
||||
debug.Enable()
|
||||
cli.api.EnableProfiler()
|
||||
}
|
||||
|
||||
|
@ -488,7 +488,7 @@ func initRouter(s *apiserver.Server, d *daemon.Daemon, c *cluster.Cluster) {
|
|||
}
|
||||
}
|
||||
|
||||
s.InitRouter(utils.IsDebugEnabled(), routers...)
|
||||
s.InitRouter(debug.IsEnabled(), routers...)
|
||||
}
|
||||
|
||||
func (cli *DaemonCli) initMiddlewares(s *apiserver.Server, cfg *apiserver.Config) error {
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/api"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/cli/debug"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
"github.com/docker/docker/pkg/fileutils"
|
||||
|
@ -19,7 +20,6 @@ import (
|
|||
"github.com/docker/docker/pkg/sysinfo"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"github.com/docker/docker/registry"
|
||||
"github.com/docker/docker/utils"
|
||||
"github.com/docker/docker/volume/drivers"
|
||||
"github.com/docker/go-connections/sockets"
|
||||
)
|
||||
|
@ -102,7 +102,7 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
|
|||
IPv4Forwarding: !sysInfo.IPv4ForwardingDisabled,
|
||||
BridgeNfIptables: !sysInfo.BridgeNFCallIPTablesDisabled,
|
||||
BridgeNfIP6tables: !sysInfo.BridgeNFCallIP6TablesDisabled,
|
||||
Debug: utils.IsDebugEnabled(),
|
||||
Debug: debug.IsEnabled(),
|
||||
NFd: fileutils.GetTotalUsedFds(),
|
||||
NGoroutines: runtime.NumGoroutine(),
|
||||
SystemTime: time.Now().Format(time.RFC3339Nano),
|
||||
|
|
Loading…
Reference in a new issue