Move debug functions to cli/debug package

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2016-12-12 09:33:58 +01:00
parent 8c1ac81665
commit ce37550347
No known key found for this signature in database
GPG key ID: 083CC6FD6EB699A3
7 changed files with 31 additions and 31 deletions

View file

@ -12,8 +12,8 @@ import (
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/docker/docker/cli/debug"
"github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/utils"
"github.com/docker/docker/utils/templates" "github.com/docker/docker/utils/templates"
"github.com/docker/go-units" "github.com/docker/go-units"
"github.com/spf13/cobra" "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(), "Name: %s\n", info.Name)
ioutils.FprintfIfNotEmpty(dockerCli.Out(), "ID: %s\n", info.ID) ioutils.FprintfIfNotEmpty(dockerCli.Out(), "ID: %s\n", info.ID)
fmt.Fprintf(dockerCli.Out(), "Docker Root Dir: %s\n", info.DockerRootDir) 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) fmt.Fprintf(dockerCli.Out(), "Debug Mode (server): %v\n", info.Debug)
if info.Debug { if info.Debug {

View file

@ -1,4 +1,4 @@
package utils package debug
import ( import (
"os" "os"
@ -6,21 +6,21 @@ import (
"github.com/Sirupsen/logrus" "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. // and makes the logger to log at debug level.
func EnableDebug() { func Enable() {
os.Setenv("DEBUG", "1") os.Setenv("DEBUG", "1")
logrus.SetLevel(logrus.DebugLevel) 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. // and makes the logger to log at info level.
func DisableDebug() { func Disable() {
os.Setenv("DEBUG", "") os.Setenv("DEBUG", "")
logrus.SetLevel(logrus.InfoLevel) logrus.SetLevel(logrus.InfoLevel)
} }
// IsDebugEnabled checks whether the debug flag is set or not. // IsEnabled checks whether the debug flag is set or not.
func IsDebugEnabled() bool { func IsEnabled() bool {
return os.Getenv("DEBUG") != "" return os.Getenv("DEBUG") != ""
} }

View file

@ -1,4 +1,4 @@
package utils package debug
import ( import (
"os" "os"
@ -7,12 +7,12 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
) )
func TestEnableDebug(t *testing.T) { func TestEnable(t *testing.T) {
defer func() { defer func() {
os.Setenv("DEBUG", "") os.Setenv("DEBUG", "")
logrus.SetLevel(logrus.InfoLevel) logrus.SetLevel(logrus.InfoLevel)
}() }()
EnableDebug() Enable()
if os.Getenv("DEBUG") != "1" { if os.Getenv("DEBUG") != "1" {
t.Fatalf("expected DEBUG=1, got %s\n", os.Getenv("DEBUG")) 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) { func TestDisable(t *testing.T) {
DisableDebug() Disable()
if os.Getenv("DEBUG") != "" { if os.Getenv("DEBUG") != "" {
t.Fatalf("expected DEBUG=\"\", got %s\n", 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) { func TestEnabled(t *testing.T) {
EnableDebug() Enable()
if !IsDebugEnabled() { if !IsEnabled() {
t.Fatal("expected debug enabled, got false") t.Fatal("expected debug enabled, got false")
} }
DisableDebug() Disable()
if IsDebugEnabled() { if IsEnabled() {
t.Fatal("expected debug disabled, got true") t.Fatal("expected debug disabled, got true")
} }
} }

View file

@ -10,11 +10,11 @@ import (
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/docker/docker/cli/command/commands" "github.com/docker/docker/cli/command/commands"
"github.com/docker/docker/cli/debug"
cliflags "github.com/docker/docker/cli/flags" cliflags "github.com/docker/docker/cli/flags"
"github.com/docker/docker/cliconfig" "github.com/docker/docker/cliconfig"
"github.com/docker/docker/dockerversion" "github.com/docker/docker/dockerversion"
"github.com/docker/docker/pkg/term" "github.com/docker/docker/pkg/term"
"github.com/docker/docker/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )
@ -130,7 +130,7 @@ func dockerPreRun(opts *cliflags.ClientOptions) {
} }
if opts.Common.Debug { if opts.Common.Debug {
utils.EnableDebug() debug.Enable()
} }
} }

View file

@ -7,12 +7,12 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/docker/docker/cli/debug"
"github.com/docker/docker/pkg/testutil/assert" "github.com/docker/docker/pkg/testutil/assert"
"github.com/docker/docker/utils"
) )
func TestClientDebugEnabled(t *testing.T) { func TestClientDebugEnabled(t *testing.T) {
defer utils.DisableDebug() defer debug.Disable()
cmd := newDockerCommand(&command.DockerCli{}) cmd := newDockerCommand(&command.DockerCli{})
cmd.Flags().Set("debug", "true") cmd.Flags().Set("debug", "true")

View file

@ -26,6 +26,7 @@ import (
systemrouter "github.com/docker/docker/api/server/router/system" systemrouter "github.com/docker/docker/api/server/router/system"
"github.com/docker/docker/api/server/router/volume" "github.com/docker/docker/api/server/router/volume"
"github.com/docker/docker/builder/dockerfile" "github.com/docker/docker/builder/dockerfile"
"github.com/docker/docker/cli/debug"
cliflags "github.com/docker/docker/cli/flags" cliflags "github.com/docker/docker/cli/flags"
"github.com/docker/docker/cliconfig" "github.com/docker/docker/cliconfig"
"github.com/docker/docker/daemon" "github.com/docker/docker/daemon"
@ -44,7 +45,6 @@ import (
"github.com/docker/docker/plugin" "github.com/docker/docker/plugin"
"github.com/docker/docker/registry" "github.com/docker/docker/registry"
"github.com/docker/docker/runconfig" "github.com/docker/docker/runconfig"
"github.com/docker/docker/utils"
"github.com/docker/go-connections/tlsconfig" "github.com/docker/go-connections/tlsconfig"
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )
@ -137,7 +137,7 @@ func (cli *DaemonCli) start(opts daemonOptions) (err error) {
} }
if cli.Config.Debug { if cli.Config.Debug {
utils.EnableDebug() debug.Enable()
} }
if cli.Config.Experimental { if cli.Config.Experimental {
@ -351,13 +351,13 @@ func (cli *DaemonCli) reloadConfig() {
} }
if config.IsValueSet("debug") { if config.IsValueSet("debug") {
debugEnabled := utils.IsDebugEnabled() debugEnabled := debug.IsEnabled()
switch { switch {
case debugEnabled && !config.Debug: // disable debug case debugEnabled && !config.Debug: // disable debug
utils.DisableDebug() debug.Disable()
cli.api.DisableProfiler() cli.api.DisableProfiler()
case config.Debug && !debugEnabled: // enable debug case config.Debug && !debugEnabled: // enable debug
utils.EnableDebug() debug.Enable()
cli.api.EnableProfiler() 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 { func (cli *DaemonCli) initMiddlewares(s *apiserver.Server, cfg *apiserver.Config) error {

View file

@ -10,6 +10,7 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/api" "github.com/docker/docker/api"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/cli/debug"
"github.com/docker/docker/container" "github.com/docker/docker/container"
"github.com/docker/docker/dockerversion" "github.com/docker/docker/dockerversion"
"github.com/docker/docker/pkg/fileutils" "github.com/docker/docker/pkg/fileutils"
@ -19,7 +20,6 @@ import (
"github.com/docker/docker/pkg/sysinfo" "github.com/docker/docker/pkg/sysinfo"
"github.com/docker/docker/pkg/system" "github.com/docker/docker/pkg/system"
"github.com/docker/docker/registry" "github.com/docker/docker/registry"
"github.com/docker/docker/utils"
"github.com/docker/docker/volume/drivers" "github.com/docker/docker/volume/drivers"
"github.com/docker/go-connections/sockets" "github.com/docker/go-connections/sockets"
) )
@ -102,7 +102,7 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
IPv4Forwarding: !sysInfo.IPv4ForwardingDisabled, IPv4Forwarding: !sysInfo.IPv4ForwardingDisabled,
BridgeNfIptables: !sysInfo.BridgeNFCallIPTablesDisabled, BridgeNfIptables: !sysInfo.BridgeNFCallIPTablesDisabled,
BridgeNfIP6tables: !sysInfo.BridgeNFCallIP6TablesDisabled, BridgeNfIP6tables: !sysInfo.BridgeNFCallIP6TablesDisabled,
Debug: utils.IsDebugEnabled(), Debug: debug.IsEnabled(),
NFd: fileutils.GetTotalUsedFds(), NFd: fileutils.GetTotalUsedFds(),
NGoroutines: runtime.NumGoroutine(), NGoroutines: runtime.NumGoroutine(),
SystemTime: time.Now().Format(time.RFC3339Nano), SystemTime: time.Now().Format(time.RFC3339Nano),