Add --stats-log-level so can see --stats without -v - fixes #1180

The most common use for this flag is likely to be showing the stats
without using -v by using `--stats-log-level NOTICE`.
This commit is contained in:
Nick Craig-Wood
2017-06-26 22:50:37 +01:00
parent 33f302a06b
commit aa20486485
5 changed files with 54 additions and 18 deletions
+29
View File
@@ -9,6 +9,9 @@ import (
"reflect"
"runtime"
"strings"
"github.com/pkg/errors"
"github.com/spf13/pflag"
)
// LogLevel describes rclone's logs. These are a subset of the syslog log levels.
@@ -55,6 +58,25 @@ func (l LogLevel) String() string {
return logLevelToString[l]
}
// Set a LogLevel
func (l *LogLevel) Set(s string) error {
for n, name := range logLevelToString {
if s != "" && name == s {
*l = LogLevel(n)
return nil
}
}
return errors.Errorf("Unknown log level %q", s)
}
// Type of the value
func (l *LogLevel) Type() string {
return "string"
}
// Check it satisfies the interface
var _ pflag.Value = (*LogLevel)(nil)
// Flags
var (
logFile = StringP("log-file", "", "", "Log everything to this file")
@@ -77,6 +99,13 @@ func logPrintf(level LogLevel, o interface{}, text string, args ...interface{})
logPrint(level, out)
}
// LogLevelPrintf writes logs at the given level
func LogLevelPrintf(level LogLevel, o interface{}, text string, args ...interface{}) {
if Config.LogLevel >= level {
logPrintf(level, o, text, args...)
}
}
// Errorf writes error log output for this Object or Fs. It
// should always be seen by the user.
func Errorf(o interface{}, text string, args ...interface{}) {