logger.go 378 B

123456789101112131415161718
  1. package logger
  2. import (
  3. "log"
  4. "os"
  5. "useEquipmentTimeEarlyWARNING/config"
  6. )
  7. func init() {
  8. file, err := os.OpenFile("./log.txt", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
  9. if err != nil {
  10. panic("open log file error")
  11. }
  12. serialNumber := config.Config.GetString("serialNumber")
  13. log.SetFlags(log.Lshortfile | log.Ldate)
  14. log.SetPrefix(serialNumber)
  15. log.SetOutput(file)
  16. }