You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
531 B

6 years ago
  1. package main
  2. import (
  3. "io"
  4. "log"
  5. "os"
  6. "strings"
  7. "time"
  8. )
  9. func savelog() {
  10. timeS := time.Now().String()
  11. _ = os.Mkdir("logs", os.ModePerm)
  12. //next 3 lines are to avoid windows filesystem errors
  13. timeS = strings.Replace(timeS, " ", "_", -1)
  14. timeS = strings.Replace(timeS, ".", "-", -1)
  15. timeS = strings.Replace(timeS, ":", "-", -1)
  16. logFile, err := os.OpenFile("logs/log-"+timeS+".log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
  17. if err != nil {
  18. panic(err)
  19. }
  20. mw := io.MultiWriter(os.Stdout, logFile)
  21. log.SetOutput(mw)
  22. }