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.

40 lines
733 B

  1. package logger
  2. import (
  3. "fmt"
  4. "os"
  5. "path"
  6. "runtime"
  7. "time"
  8. )
  9. // 获取今天的日期
  10. func getToday() string {
  11. now := time.Now()
  12. return now.Format("2006-01-02")
  13. }
  14. // 获取当前时间
  15. func getCurrentTime() string {
  16. now := time.Now()
  17. hour := now.Hour()
  18. minute := now.Minute()
  19. second := now.Second()
  20. return fmt.Sprintf("%02d:%02d:%02d", hour, minute, second)
  21. }
  22. // 获取调用代码的位置信息
  23. func getCaller(skip int) string {
  24. pc, file, line, ok := runtime.Caller(skip)
  25. if !ok {
  26. return ""
  27. }
  28. fileName := path.Base(file)
  29. funcName := runtime.FuncForPC(pc).Name()
  30. return fmt.Sprintf("file:%v;function:%v;line:%d", fileName, funcName, line)
  31. }
  32. // 获取程序进程id
  33. func getPid() int {
  34. return os.Getpid()
  35. }