Skip to content

Commit

Permalink
Merge pull request #312 from baude/logfile
Browse files Browse the repository at this point in the history
Add --log-file to gvproxy
  • Loading branch information
openshift-merge-bot[bot] authored Jan 16, 2024
2 parents f20bbe0 + 4c2c7bb commit 012bc90
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cmd/gvproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
sshPort int
pidFile string
exitCode int
logFile string
)

const (
Expand Down Expand Up @@ -72,13 +73,30 @@ func main() {
flag.Var(&forwardUser, "forward-user", "SSH user to use for unix socket forward")
flag.Var(&forwardIdentify, "forward-identity", "Path to SSH identity key for forwarding")
flag.StringVar(&pidFile, "pid-file", "", "Generate a file with the PID in it")
flag.StringVar(&logFile, "log-file", "", "Output log messages (logrus) to a given file path")
flag.Parse()

if version.ShowVersion() {
fmt.Println(version.String())
os.Exit(0)
}

// If the user provides a log-file, we re-direct log messages
// from logrus to the file
if logFile != "" {
lf, err := os.Create(logFile)
if err != nil {
fmt.Printf("unable to open log file %s, exiting...\n", logFile)
os.Exit(1)
}
defer func() {
if err := lf.Close(); err != nil {
fmt.Printf("unable to close log-file: %q\n", err)
}
}()
log.SetOutput(lf)
}

log.Infof(version.String())
ctx, cancel := context.WithCancel(context.Background())
// Make this the last defer statement in the stack
Expand Down

0 comments on commit 012bc90

Please sign in to comment.