mirror of
https://github.com/zrepl/zrepl.git
synced 2025-02-16 18:30:54 +01:00
cmd: remove stderrFile option
This commit is contained in:
parent
3fd9726719
commit
71650819d3
24
cmd/main.go
24
cmd/main.go
@ -11,10 +11,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
"io"
|
|
||||||
golog "log"
|
golog "log"
|
||||||
"net/http"
|
"net/http"
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
@ -29,7 +26,6 @@ type Logger interface {
|
|||||||
var (
|
var (
|
||||||
conf *Config
|
conf *Config
|
||||||
logFlags int = golog.LUTC | golog.Ldate | golog.Ltime
|
logFlags int = golog.LUTC | golog.Ldate | golog.Ltime
|
||||||
logOut io.Writer
|
|
||||||
log Logger
|
log Logger
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -46,36 +42,18 @@ var RootCmd = &cobra.Command{
|
|||||||
|
|
||||||
var rootArgs struct {
|
var rootArgs struct {
|
||||||
configFile string
|
configFile string
|
||||||
stderrFile string
|
|
||||||
httpPprof string
|
httpPprof string
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cobra.OnInitialize(initConfig)
|
cobra.OnInitialize(initConfig)
|
||||||
RootCmd.PersistentFlags().StringVar(&rootArgs.configFile, "config", "", "config file path")
|
RootCmd.PersistentFlags().StringVar(&rootArgs.configFile, "config", "", "config file path")
|
||||||
RootCmd.PersistentFlags().StringVar(&rootArgs.stderrFile, "stderrFile", "-", "redirect stderr to given path")
|
|
||||||
RootCmd.PersistentFlags().StringVar(&rootArgs.httpPprof, "debug.pprof.http", "", "run pprof http server on given port")
|
RootCmd.PersistentFlags().StringVar(&rootArgs.httpPprof, "debug.pprof.http", "", "run pprof http server on given port")
|
||||||
}
|
}
|
||||||
|
|
||||||
func initConfig() {
|
func initConfig() {
|
||||||
|
|
||||||
// Logging & stderr redirection
|
log = golog.New(os.Stderr, "", logFlags)
|
||||||
if rootArgs.stderrFile != "-" {
|
|
||||||
file, err := os.OpenFile(rootArgs.stderrFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = unix.Dup2(int(file.Fd()), int(os.Stderr.Fd())); err != nil {
|
|
||||||
file.WriteString(fmt.Sprintf("error redirecting stderr file %s: %s\n", rootArgs.stderrFile, err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
logOut = file
|
|
||||||
} else {
|
|
||||||
logOut = os.Stderr
|
|
||||||
}
|
|
||||||
|
|
||||||
log = golog.New(logOut, "", logFlags)
|
|
||||||
|
|
||||||
// CPU profiling
|
// CPU profiling
|
||||||
if rootArgs.httpPprof != "" {
|
if rootArgs.httpPprof != "" {
|
||||||
|
Loading…
Reference in New Issue
Block a user