diff --git a/docs/content/docs.md b/docs/content/docs.md index a1c589740..e558c12d5 100644 --- a/docs/content/docs.md +++ b/docs/content/docs.md @@ -415,7 +415,8 @@ using `--checksum`). Log all of rclone's output to FILE. This is not active by default. This can be useful for tracking down problems with syncs in -combination with the `-v` flag. +combination with the `-v` flag. See the Logging section for more +info. ### --low-level-retries NUMBER ### @@ -705,6 +706,25 @@ For the filtering options See the [filtering section](/filtering/). +Logging +------- + +rclone has 3 levels of logging, `Error`, `Info` and `Debug`. + +By default rclone logs `Error` and `Info` to standard error and `Debug` +to standard output. This means you can redirect standard output and +standard error to different places. + +By default rclone will produce `Error` and `Info` level messages. + +If you use the `-q` flag, rclone will only produce `Error` messages. + +If you use the `-v` flag, rclone will produce `Error`, `Info` and +`Debug` messages. + +If you use the `--log-file=FILE` option, rclone will redirect `Error`, +`Info` and `Debug` messages along with standard error to FILE. + Exit Code --------- diff --git a/fs/fs.go b/fs/fs.go index 20f996ca6..e81bc25bd 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -6,6 +6,7 @@ import ( "io" "log" "math" + "os" "path/filepath" "regexp" "sort" @@ -357,27 +358,30 @@ func NewFs(path string) (Fs, error) { return fs.NewFs(configName, fsPath) } -// OutputLog logs for an object -func OutputLog(o interface{}, text string, args ...interface{}) { - description := "" - if o != nil { - description = fmt.Sprintf("%v: ", o) - } +// 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...) - log.Print(description + out) + if o == nil { + return out + } + return fmt.Sprintf("%v: %s", o, out) } -// Debug writes debuging output for this Object or Fs +// Debug writes debugging output for this Object or Fs func Debug(o interface{}, text string, args ...interface{}) { if Config.Verbose { - OutputLog(o, text, args...) + DebugLogger.Print(makeLog(o, text, args...)) } } -// Log writes log output for this Object or Fs +// Log writes log output for this Object or Fs. This should be +// considered to be Info level logging. func Log(o interface{}, text string, args ...interface{}) { if !Config.Quiet { - OutputLog(o, text, args...) + log.Print(makeLog(o, text, args...)) } } @@ -385,7 +389,7 @@ func Log(o interface{}, text string, args ...interface{}) { // unconditionally logs a message regardless of Config.Quiet or // Config.Verbose. func ErrorLog(o interface{}, text string, args ...interface{}) { - OutputLog(o, text, args...) + log.Print(makeLog(o, text, args...)) } // CheckClose is a utility function used to check the return from diff --git a/rclone.go b/rclone.go index 8186b3797..98d40bc19 100644 --- a/rclone.go +++ b/rclone.go @@ -411,6 +411,7 @@ func main() { log.Printf("Failed to seek log file to end: %v", err) } log.SetOutput(f) + fs.DebugLogger.SetOutput(f) redirectStderr(f) }