mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 10:58:55 +00:00
Allow debug logging to pipes and terminals
This commit is contained in:
parent
96a912b65a
commit
63be3704d9
@ -12,8 +12,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/restic/restic/internal/fs"
|
"github.com/restic/restic/internal/fs"
|
||||||
|
|
||||||
"github.com/restic/restic/internal/errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var opts struct {
|
var opts struct {
|
||||||
@ -50,20 +48,7 @@ func initDebugLogger() {
|
|||||||
|
|
||||||
fmt.Fprintf(os.Stderr, "debug log file %v\n", debugfile)
|
fmt.Fprintf(os.Stderr, "debug log file %v\n", debugfile)
|
||||||
|
|
||||||
f, err := fs.OpenFile(debugfile, os.O_WRONLY|os.O_APPEND, 0600)
|
f, err := fs.OpenFile(debugfile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
_, err = f.Seek(2, 0)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "unable to seek to the end of %v: %v\n", debugfile, err)
|
|
||||||
os.Exit(3)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil && os.IsNotExist(errors.Cause(err)) {
|
|
||||||
f, err = fs.OpenFile(debugfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "unable to open debug log file: %v\n", err)
|
fmt.Fprintf(os.Stderr, "unable to open debug log file: %v\n", err)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
|
Loading…
Reference in New Issue
Block a user