mirror of
https://github.com/containers/gvisor-tap-vsock.git
synced 2025-12-24 13:29:22 +08:00
Add --log-file to gvproxy
Add ability specify a log-file for log messages. This PR redirects are logged messages from the logrus logger to a given file. It is intended to help debug gvproxy failures and usage. Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
@@ -45,6 +45,7 @@ var (
|
||||
sshPort int
|
||||
pidFile string
|
||||
exitCode int
|
||||
logFile string
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -72,6 +73,7 @@ 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() {
|
||||
@@ -79,6 +81,22 @@ func main() {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user