Redo log level flags

* -vv or --log-level DEBUG
  * -v or --log-level INFO
  * --log-level NOTICE (default)
  * -q --log-level ERROR

Replace Config.Verbose and Config.Quiet with Config.LogLevel

Fixes #739 Fixes #1108 Fixes #1000
This commit is contained in:
Nick Craig-Wood
2017-02-09 21:22:46 +00:00
parent 0366ea39c5
commit ac1c041377
9 changed files with 137 additions and 40 deletions

View File

@@ -11,9 +11,11 @@ import (
// LogLevel describes rclone's logs. These are a subset of the syslog log levels.
type LogLevel byte
//go:generate stringer -type=LogLevel
// Log levels - a subset of the syslog logs
const (
LogLevelEmergency = iota
LogLevelEmergency LogLevel = iota
LogLevelAlert
LogLevelCritical
LogLevelError // Error - can't be suppressed
@@ -38,30 +40,37 @@ func makeLog(o interface{}, text string, args ...interface{}) string {
}
// Errorf writes error log output for this Object or Fs. It
// unconditionally logs a message regardless of Config.Quiet or
// Config.Verbose.
// unconditionally logs a message regardless of Config.LogLevel
func Errorf(o interface{}, text string, args ...interface{}) {
log.Print(makeLog(o, text, args...))
}
// Logf writes log output for this Object or Fs. This should be
// considered to be Info level logging.
func Logf(o interface{}, text string, args ...interface{}) {
if !Config.Quiet {
if Config.LogLevel >= LogLevelError {
log.Print(makeLog(o, text, args...))
}
}
// Infof writes info on transfers for this Object or Fs
// Logf writes log output for this Object or Fs. This should be
// considered to be Info level logging. It is the default level. By
// default rclone should not log very much so only use this for
// important things the user should see. The user can filter these
// out with the -q flag.
func Logf(o interface{}, text string, args ...interface{}) {
if Config.LogLevel >= LogLevelNotice {
log.Print(makeLog(o, text, args...))
}
}
// Infof writes info on transfers for this Object or Fs. Use this
// level for logging transfers, deletions and things which should
// appear with the -v flag.
func Infof(o interface{}, text string, args ...interface{}) {
if Config.Verbose {
if Config.LogLevel >= LogLevelInfo {
DebugLogger.Print(makeLog(o, text, args...))
}
}
// Debugf writes debugging output for this Object or Fs
// Debugf writes debugging output for this Object or Fs. Use this for
// debug only. The user must have to specify -vv to see this.
func Debugf(o interface{}, text string, args ...interface{}) {
if Config.Verbose {
if Config.LogLevel >= LogLevelDebug {
DebugLogger.Print(makeLog(o, text, args...))
}
}