glog.go 632 B

123456789101112131415161718192021222324252627282930313233
  1. package glog
  2. import (
  3. "log"
  4. "os"
  5. "strings"
  6. "time"
  7. )
  8. // @title XWarning
  9. // @description warning日志输出
  10. // @param
  11. // @return
  12. func XWarning(content string) {
  13. log.Printf(content)
  14. LogWrite(content)
  15. }
  16. // @title LogWrite
  17. // @description log信息写入log文件
  18. // @param
  19. // @return
  20. func LogWrite(content string) {
  21. //使用当前项目路径
  22. fd, _ := os.OpenFile("log.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
  23. fd_time := time.Now().Format("2006-01-02 15:04:05")
  24. fd_content := strings.Join([]string{"======", fd_time, "=====", content, "\n"}, "")
  25. buf := []byte(fd_content)
  26. fd.Write(buf)
  27. fd.Close()
  28. }