forked from TrueCloudLab/rclone
Log -v output to stdout by default - fixes #228
This commit is contained in:
parent
f15e7e89d2
commit
108760e17b
3 changed files with 38 additions and 13 deletions
|
@ -415,7 +415,8 @@ using `--checksum`).
|
||||||
|
|
||||||
Log all of rclone's output to FILE. This is not active by default.
|
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
|
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 ###
|
### --low-level-retries NUMBER ###
|
||||||
|
|
||||||
|
@ -705,6 +706,25 @@ For the filtering options
|
||||||
|
|
||||||
See the [filtering section](/filtering/).
|
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
|
Exit Code
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
|
28
fs/fs.go
28
fs/fs.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -357,27 +358,30 @@ func NewFs(path string) (Fs, error) {
|
||||||
return fs.NewFs(configName, fsPath)
|
return fs.NewFs(configName, fsPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OutputLog logs for an object
|
// DebugLogger - logs to Stdout
|
||||||
func OutputLog(o interface{}, text string, args ...interface{}) {
|
var DebugLogger = log.New(os.Stdout, "", log.LstdFlags)
|
||||||
description := ""
|
|
||||||
if o != nil {
|
// makeLog produces a log string from the arguments passed in
|
||||||
description = fmt.Sprintf("%v: ", o)
|
func makeLog(o interface{}, text string, args ...interface{}) string {
|
||||||
}
|
|
||||||
out := fmt.Sprintf(text, args...)
|
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{}) {
|
func Debug(o interface{}, text string, args ...interface{}) {
|
||||||
if Config.Verbose {
|
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{}) {
|
func Log(o interface{}, text string, args ...interface{}) {
|
||||||
if !Config.Quiet {
|
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
|
// unconditionally logs a message regardless of Config.Quiet or
|
||||||
// Config.Verbose.
|
// Config.Verbose.
|
||||||
func ErrorLog(o interface{}, text string, args ...interface{}) {
|
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
|
// CheckClose is a utility function used to check the return from
|
||||||
|
|
|
@ -411,6 +411,7 @@ func main() {
|
||||||
log.Printf("Failed to seek log file to end: %v", err)
|
log.Printf("Failed to seek log file to end: %v", err)
|
||||||
}
|
}
|
||||||
log.SetOutput(f)
|
log.SetOutput(f)
|
||||||
|
fs.DebugLogger.SetOutput(f)
|
||||||
redirectStderr(f)
|
redirectStderr(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue