mirror of https://github.com/docker/docs.git
Change default log level to fatal, change verbose to error level and add
debug flag for debug level Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
This commit is contained in:
parent
ffe603a968
commit
12d3eb49ae
|
@ -822,6 +822,28 @@ func TestDefaultRootKeyGeneration(t *testing.T) {
|
|||
assertNumKeys(t, tempDir, 1, 0, true)
|
||||
}
|
||||
|
||||
// Tests the interaction with the verbose and log-level flags
|
||||
func TestLogLevelFlags(t *testing.T) {
|
||||
// Test default to fatal
|
||||
setVerbosityLevel()
|
||||
assert.Equal(t, "fatal", logrus.GetLevel().String())
|
||||
|
||||
// Test that verbose (-v) sets to error
|
||||
verbose = true
|
||||
setVerbosityLevel()
|
||||
assert.Equal(t, "error", logrus.GetLevel().String())
|
||||
|
||||
// Test that debug (-D) sets to debug
|
||||
debug = true
|
||||
setVerbosityLevel()
|
||||
assert.Equal(t, "debug", logrus.GetLevel().String())
|
||||
|
||||
// Test that unsetting verboseError still uses verboseDebug
|
||||
verbose = false
|
||||
setVerbosityLevel()
|
||||
assert.Equal(t, "debug", logrus.GetLevel().String())
|
||||
}
|
||||
|
||||
func tempDirWithConfig(t *testing.T, config string) string {
|
||||
tempDir, err := ioutil.TempDir("/tmp", "repo")
|
||||
assert.NoError(t, err)
|
||||
|
|
|
@ -20,6 +20,7 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
debug bool
|
||||
verbose bool
|
||||
trustDir string
|
||||
configFile string
|
||||
|
@ -37,10 +38,7 @@ func init() {
|
|||
}
|
||||
|
||||
func parseConfig() *viper.Viper {
|
||||
if verbose {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
logrus.SetOutput(os.Stderr)
|
||||
}
|
||||
setVerbosityLevel()
|
||||
|
||||
// Get home directory for current user
|
||||
homeDir, err := homedir.Dir()
|
||||
|
@ -112,6 +110,7 @@ func setupCommand(notaryCmd *cobra.Command) {
|
|||
notaryCmd.PersistentFlags().StringVarP(&trustDir, "trustDir", "d", "", "Directory where the trust data is persisted to")
|
||||
notaryCmd.PersistentFlags().StringVarP(&configFile, "configFile", "c", "", "Path to the configuration file to use")
|
||||
notaryCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Verbose output")
|
||||
notaryCmd.PersistentFlags().BoolVarP(&debug, "debug", "D", false, "Debug output")
|
||||
notaryCmd.PersistentFlags().StringVarP(&remoteTrustServer, "server", "s", "", "Remote trust server location")
|
||||
|
||||
cmdKeyGenerator := &keyCommander{
|
||||
|
@ -180,3 +179,15 @@ func getPassphraseRetriever() passphrase.Retriever {
|
|||
return baseRetriever(keyName, alias, createNew, numAttempts)
|
||||
}
|
||||
}
|
||||
|
||||
// Set the logging level to fatal on default, or the most specific level the user specified (debug or error)
|
||||
func setVerbosityLevel() {
|
||||
if debug {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
} else if verbose {
|
||||
logrus.SetLevel(logrus.ErrorLevel)
|
||||
} else {
|
||||
logrus.SetLevel(logrus.FatalLevel)
|
||||
}
|
||||
logrus.SetOutput(os.Stderr)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue