Skip to content

Commit

Permalink
Create correctly log files/directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz 'Serafin' Gajewski committed Aug 23, 2017
1 parent 5f8340c commit cc7a548
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 3 additions & 5 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cc7a548

Please sign in to comment.