X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=main.go;fp=main.go;h=4fd49e9137a5fb59e0a4b5a7c663ce02b5f86ea5;hb=347bd1674bbf67ccb6209951a4bf8f2971715532;hp=65ab7a0a887ed05f51cd6f596a573e7441f178e1;hpb=2fed63ed0087df0c79f7f30f7f397611381bfccd;p=src%2Fxds%2Fxds-server.git diff --git a/main.go b/main.go index 65ab7a0..4fd49e9 100644 --- a/main.go +++ b/main.go @@ -117,22 +117,34 @@ func xdsApp(cliCtx *cli.Context) error { // Logs redirected into a file when logsDir is set logfilename := cliCtx.GlobalString("logfile") - if ctx.Config.FileConf.LogsDir != "" && logfilename != "stdout" { - if logfilename == "" { - logfilename = "xds-server.log" - } - // is it an absolute path ? - logFile := logfilename - if logfilename[0] == '.' || logfilename[0] != '/' { - logFile = filepath.Join(ctx.Config.FileConf.LogsDir, logfilename) + ctx.Config.LogVerboseOut = os.Stderr + if ctx.Config.FileConf.LogsDir != "" { + if logfilename != "stdout" { + if logfilename == "" { + logfilename = "xds-server.log" + } + // is it an absolute path ? + logFile := logfilename + if logfilename[0] == '.' || logfilename[0] != '/' { + logFile = filepath.Join(ctx.Config.FileConf.LogsDir, logfilename) + } + fmt.Printf("Logging file: %s\n", logFile) + fdL, err := os.OpenFile(logFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666) + if err != nil { + msgErr := fmt.Sprintf("Cannot create log file %s", logFile) + return cli.NewExitError(msgErr, int(syscall.EPERM)) + } + ctx.Log.Out = fdL } - fmt.Printf("Logging file: %s\n", logFile) - fdL, err := os.OpenFile(logFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666) + + logFileHTTPReq := filepath.Join(ctx.Config.FileConf.LogsDir, "xds-server-verbose.log") + fmt.Printf("Logging file for HTTP requests: %s\n", logFileHTTPReq) + fdLH, err := os.OpenFile(logFileHTTPReq, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666) if err != nil { - msgErr := fmt.Sprintf("Cannot create log file %s", logFile) + msgErr := fmt.Sprintf("Cannot create log file %s", logFileHTTPReq) return cli.NewExitError(msgErr, int(syscall.EPERM)) } - ctx.Log.Out = fdL + ctx.Config.LogVerboseOut = fdLH } // Create syncthing instance when section "syncthing" is present in config.json