summaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-08-24 21:23:40 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-08-24 21:28:28 +0200
commit347bd1674bbf67ccb6209951a4bf8f2971715532 (patch)
treeb34495fe40d7cf6c0d08a5b9a6b977b3981f9496 /main.go
parent2fed63ed0087df0c79f7f30f7f397611381bfccd (diff)
Redirect HTTP and Gin server logs into a file (xds-server-verbose.log).
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'main.go')
-rw-r--r--main.go36
1 files changed, 24 insertions, 12 deletions
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