mirror of https://github.com/rclone/rclone.git
Add --log-file flag to log everything (including panics) to file
This commit is contained in:
parent
e89ea3360e
commit
24a6ff54c2
|
@ -125,15 +125,17 @@ the same format as the standard md5sum tool produces.
|
||||||
General options:
|
General options:
|
||||||
|
|
||||||
```
|
```
|
||||||
--bwlimit=0: Bandwidth limit in kBytes/s, or use suffix k|M|G
|
--bwlimit=0: Bandwidth limit in kBytes/s, or use suffix K|M|G
|
||||||
--checkers=8: Number of checkers to run in parallel.
|
--checkers=8: Number of checkers to run in parallel.
|
||||||
--config="~/.rclone.conf": Config file.
|
--config="~/.rclone.conf": Config file.
|
||||||
-n, --dry-run=false: Do a trial run with no permanent changes
|
-n, --dry-run=false: Do a trial run with no permanent changes
|
||||||
|
--log-file="": Log everything to this file
|
||||||
--modify-window=1ns: Max time diff to be considered the same
|
--modify-window=1ns: Max time diff to be considered the same
|
||||||
-q, --quiet=false: Print as little stuff as possible
|
-q, --quiet=false: Print as little stuff as possible
|
||||||
--stats=1m0s: Interval to print stats
|
--stats=1m0s: Interval to print stats (0 to disable)
|
||||||
--transfers=4: Number of file transfers to run in parallel.
|
--transfers=4: Number of file transfers to run in parallel.
|
||||||
-v, --verbose=false: Print lots more stuff
|
-v, --verbose=false: Print lots more stuff
|
||||||
|
-V, --version=false: Print the version number
|
||||||
```
|
```
|
||||||
|
|
||||||
Developer options:
|
Developer options:
|
||||||
|
|
|
@ -107,15 +107,17 @@ the same format as the standard md5sum tool produces.
|
||||||
General options:
|
General options:
|
||||||
|
|
||||||
```
|
```
|
||||||
--bwlimit=0: Bandwidth limit in kBytes/s, or use suffix k|M|G
|
--bwlimit=0: Bandwidth limit in kBytes/s, or use suffix K|M|G
|
||||||
--checkers=8: Number of checkers to run in parallel.
|
--checkers=8: Number of checkers to run in parallel.
|
||||||
--transfers=4: Number of file transfers to run in parallel.
|
|
||||||
--config="~/.rclone.conf": Config file.
|
--config="~/.rclone.conf": Config file.
|
||||||
-n, --dry-run=false: Do a trial run with no permanent changes
|
-n, --dry-run=false: Do a trial run with no permanent changes
|
||||||
|
--log-file="": Log everything to this file
|
||||||
--modify-window=1ns: Max time diff to be considered the same
|
--modify-window=1ns: Max time diff to be considered the same
|
||||||
-q, --quiet=false: Print as little stuff as possible
|
-q, --quiet=false: Print as little stuff as possible
|
||||||
--stats=1m0s: Interval to print stats
|
--stats=1m0s: Interval to print stats (0 to disable)
|
||||||
|
--transfers=4: Number of file transfers to run in parallel.
|
||||||
-v, --verbose=false: Print lots more stuff
|
-v, --verbose=false: Print lots more stuff
|
||||||
|
-V, --version=false: Print the version number
|
||||||
```
|
```
|
||||||
|
|
||||||
Developer options:
|
Developer options:
|
||||||
|
|
12
rclone.go
12
rclone.go
|
@ -30,6 +30,7 @@ var (
|
||||||
cpuprofile = pflag.StringP("cpuprofile", "", "", "Write cpu profile to file")
|
cpuprofile = pflag.StringP("cpuprofile", "", "", "Write cpu profile to file")
|
||||||
statsInterval = pflag.DurationP("stats", "", time.Minute*1, "Interval to print stats (0 to disable)")
|
statsInterval = pflag.DurationP("stats", "", time.Minute*1, "Interval to print stats (0 to disable)")
|
||||||
version = pflag.BoolP("version", "V", false, "Print the version number")
|
version = pflag.BoolP("version", "V", false, "Print the version number")
|
||||||
|
logFile = pflag.StringP("log-file", "", "", "Log everything to this file")
|
||||||
)
|
)
|
||||||
|
|
||||||
type Command struct {
|
type Command struct {
|
||||||
|
@ -343,6 +344,17 @@ func main() {
|
||||||
}
|
}
|
||||||
command, args := ParseCommand()
|
command, args := ParseCommand()
|
||||||
|
|
||||||
|
// Log file output
|
||||||
|
if *logFile != "" {
|
||||||
|
f, err := os.OpenFile(*logFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0640)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to open log file: %v", err)
|
||||||
|
}
|
||||||
|
f.Seek(0, os.SEEK_END)
|
||||||
|
log.SetOutput(f)
|
||||||
|
redirectStderr(f)
|
||||||
|
}
|
||||||
|
|
||||||
// Make source and destination fs
|
// Make source and destination fs
|
||||||
var fdst, fsrc fs.Fs
|
var fdst, fsrc fs.Fs
|
||||||
if len(args) >= 1 {
|
if len(args) >= 1 {
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
// Log the panic to the log file - for oses which can't do this
|
||||||
|
|
||||||
|
//+build !windows,!unix
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// redirectStderr to the file passed in
|
||||||
|
func redirectStderr(f *os.File) {
|
||||||
|
log.Printf("Can't redirect stderr to file")
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
// Log the panic under unix to the log file
|
||||||
|
|
||||||
|
//+build unix
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
// redirectStderr to the file passed in
|
||||||
|
func redirectStderr(f *os.File) {
|
||||||
|
err := syscall.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to redirect stderr to file: %v", err)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
// Log the panic under windows to the log file
|
||||||
|
//
|
||||||
|
// Code from minix, via
|
||||||
|
//
|
||||||
|
// http://play.golang.org/p/kLtct7lSUg
|
||||||
|
|
||||||
|
//+build windows
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
kernel32 = syscall.MustLoadDLL("kernel32.dll")
|
||||||
|
procSetStdHandle = kernel32.MustFindProc("SetStdHandle")
|
||||||
|
)
|
||||||
|
|
||||||
|
func setStdHandle(stdhandle int32, handle syscall.Handle) error {
|
||||||
|
r0, _, e1 := syscall.Syscall(procSetStdHandle.Addr(), 2, uintptr(stdhandle), uintptr(handle), 0)
|
||||||
|
if r0 == 0 {
|
||||||
|
if e1 != 0 {
|
||||||
|
return error(e1)
|
||||||
|
}
|
||||||
|
return syscall.EINVAL
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// redirectStderr to the file passed in
|
||||||
|
func redirectStderr(f *os.File) {
|
||||||
|
err := setStdHandle(syscall.STD_ERROR_HANDLE, syscall.Handle(f.Fd()))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to redirect stderr to file: %v", err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue