mirror of
https://github.com/zrepl/zrepl.git
synced 2025-06-20 01:37:45 +02:00
cmd: dup2(logfile, stderr) if logfile set
This commit is contained in:
parent
6f84bf665d
commit
ee8b0d3781
10
cmd/main.go
10
cmd/main.go
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/zrepl/zrepl/rpc"
|
"github.com/zrepl/zrepl/rpc"
|
||||||
"github.com/zrepl/zrepl/sshbytestream"
|
"github.com/zrepl/zrepl/sshbytestream"
|
||||||
"github.com/zrepl/zrepl/zfs"
|
"github.com/zrepl/zrepl/zfs"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@ -88,10 +89,17 @@ func doSink(c *cli.Context) (err error) {
|
|||||||
|
|
||||||
var logOut io.Writer
|
var logOut io.Writer
|
||||||
if c.IsSet("logfile") {
|
if c.IsSet("logfile") {
|
||||||
logOut, err = os.OpenFile(c.String("logfile"), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)
|
var logFile *os.File
|
||||||
|
logFile, err = os.OpenFile(c.String("logfile"), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = unix.Dup2(int(logFile.Fd()), int(os.Stderr.Fd())); err != nil {
|
||||||
|
logFile.WriteString(fmt.Sprintf("error duping logfile to stderr: %s\n", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logOut = logFile
|
||||||
} else {
|
} else {
|
||||||
logOut = os.Stderr
|
logOut = os.Stderr
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user