2017-02-09 11:01:20 +00:00
|
|
|
// Logging for rclone
|
|
|
|
|
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
// LogLevel describes rclone's logs. These are a subset of the syslog log levels.
|
|
|
|
type LogLevel byte
|
|
|
|
|
2017-02-09 21:22:46 +00:00
|
|
|
//go:generate stringer -type=LogLevel
|
|
|
|
|
2017-02-09 11:01:20 +00:00
|
|
|
// Log levels - a subset of the syslog logs
|
|
|
|
const (
|
2017-02-09 21:22:46 +00:00
|
|
|
LogLevelEmergency LogLevel = iota
|
2017-02-09 11:01:20 +00:00
|
|
|
LogLevelAlert
|
|
|
|
LogLevelCritical
|
|
|
|
LogLevelError // Error - can't be suppressed
|
|
|
|
LogLevelWarning
|
|
|
|
LogLevelNotice // Normal logging, -q suppresses
|
|
|
|
LogLevelInfo // Transfers, needs -v
|
|
|
|
LogLevelDebug // Debug level, needs -vv
|
|
|
|
)
|
|
|
|
|
|
|
|
// Outside world interface
|
|
|
|
|
|
|
|
// DebugLogger - logs to Stdout
|
|
|
|
var DebugLogger = log.New(os.Stdout, "", log.LstdFlags)
|
|
|
|
|
|
|
|
// makeLog produces a log string from the arguments passed in
|
|
|
|
func makeLog(o interface{}, text string, args ...interface{}) string {
|
|
|
|
out := fmt.Sprintf(text, args...)
|
|
|
|
if o == nil {
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%v: %s", o, out)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Errorf writes error log output for this Object or Fs. It
|
2017-02-09 21:22:46 +00:00
|
|
|
// unconditionally logs a message regardless of Config.LogLevel
|
2017-02-09 11:01:20 +00:00
|
|
|
func Errorf(o interface{}, text string, args ...interface{}) {
|
2017-02-09 21:22:46 +00:00
|
|
|
if Config.LogLevel >= LogLevelError {
|
|
|
|
log.Print(makeLog(o, text, args...))
|
|
|
|
}
|
2017-02-09 11:01:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Logf writes log output for this Object or Fs. This should be
|
2017-02-09 21:22:46 +00:00
|
|
|
// 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.
|
2017-02-09 11:01:20 +00:00
|
|
|
func Logf(o interface{}, text string, args ...interface{}) {
|
2017-02-09 21:22:46 +00:00
|
|
|
if Config.LogLevel >= LogLevelNotice {
|
2017-02-09 11:01:20 +00:00
|
|
|
log.Print(makeLog(o, text, args...))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-09 21:22:46 +00:00
|
|
|
// 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.
|
2017-02-09 11:01:20 +00:00
|
|
|
func Infof(o interface{}, text string, args ...interface{}) {
|
2017-02-09 21:22:46 +00:00
|
|
|
if Config.LogLevel >= LogLevelInfo {
|
2017-02-09 11:01:20 +00:00
|
|
|
DebugLogger.Print(makeLog(o, text, args...))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-09 21:22:46 +00:00
|
|
|
// Debugf writes debugging output for this Object or Fs. Use this for
|
|
|
|
// debug only. The user must have to specify -vv to see this.
|
2017-02-09 11:01:20 +00:00
|
|
|
func Debugf(o interface{}, text string, args ...interface{}) {
|
2017-02-09 21:22:46 +00:00
|
|
|
if Config.LogLevel >= LogLevelDebug {
|
2017-02-09 11:01:20 +00:00
|
|
|
DebugLogger.Print(makeLog(o, text, args...))
|
|
|
|
}
|
|
|
|
}
|