From cc7a5480d678447ef64187d770c5589980e3e958 Mon Sep 17 00:00:00 2001 From: Mateusz 'Serafin' Gajewski Date: Wed, 23 Aug 2017 12:50:42 +0200 Subject: [PATCH] Create correctly log files/directories --- logger.go | 8 +++----- main.go | 4 +++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/logger.go b/logger.go index 42d5282..56b8998 100644 --- a/logger.go +++ b/logger.go @@ -43,8 +43,6 @@ const ( timeFormat = "15:04:05.00000000" ) -const logsDir = "logs/%s.log" - var ( responseColor = color.New(color.FgHiGreen).SprintfFunc() requestColor = color.New(color.FgHiBlue).SprintFunc() @@ -138,17 +136,17 @@ func createLogWriter(filename string) (io.Writer, error) { return os.Stdout, nil } - logFilePath := fmt.Sprintf(logsDir, filename) + logFilePath := fmt.Sprintf(*flagDirLogs + "/%s.log", filename) dir := filepath.Dir(logFilePath) if _, err := os.Stat(dir); err != nil { - if err := os.MkdirAll(dir, 0666); err != nil { + if err := os.MkdirAll(dir, os.ModePerm); err != nil { return nil, err } } - writer, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) + writer, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, os.ModePerm) if err != nil { return nil, err } diff --git a/main.go b/main.go index 2bc02eb..5894bbb 100644 --- a/main.go +++ b/main.go @@ -29,12 +29,14 @@ var ( flagQuiet = flag.Bool("q", false, "do not show logs on stdout") flagMicroseconds = flag.Bool("m", false, "display time in microseconds") flagDelta = flag.Bool("delta", false, "show delta time between log entries") + flagDirLogs = flag.String("log-dir", "logs", "logs directory") ) var protocolTargetID = center("protocol message", 36) func main() { flag.Parse() + mux := http.NewServeMux() simpleReverseProxy := httputil.NewSingleHostReverseProxy(&url.URL{Scheme: "http", Host: *flagRemote}) @@ -83,7 +85,7 @@ func main() { logger.Infof("checking protocol versions on: %s", endpoint) ver, err := checkVersion() - if err != nil { + if err != nil { protocolLogger.Errorf("could not check version: %v", err) http.Error(res, "could not check version", 500) return