mirror of
https://github.com/zrepl/zrepl.git
synced 2024-12-23 07:28:57 +01: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/sshbytestream"
|
||||
"github.com/zrepl/zrepl/zfs"
|
||||
"golang.org/x/sys/unix"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
@ -88,10 +89,17 @@ func doSink(c *cli.Context) (err error) {
|
||||
|
||||
var logOut io.Writer
|
||||
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 {
|
||||
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 {
|
||||
logOut = os.Stderr
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user