package logger
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
"runtime"
|
|
"time"
|
|
)
|
|
|
|
// 获取今天的日期
|
|
func getToday() string {
|
|
now := time.Now()
|
|
return now.Format("2006-01-02")
|
|
}
|
|
|
|
// 获取当前时间
|
|
func getCurrentTime() string {
|
|
now := time.Now()
|
|
hour := now.Hour()
|
|
minute := now.Minute()
|
|
second := now.Second()
|
|
return fmt.Sprintf("%02d:%02d:%02d", hour, minute, second)
|
|
}
|
|
|
|
// 获取调用代码的位置信息
|
|
func getCaller(skip int) string {
|
|
pc, file, line, ok := runtime.Caller(skip)
|
|
if !ok {
|
|
return ""
|
|
}
|
|
fileName := path.Base(file)
|
|
funcName := runtime.FuncForPC(pc).Name()
|
|
return fmt.Sprintf("file:%v;function:%v;line:%d", fileName, funcName, line)
|
|
}
|
|
|
|
// 获取程序进程id
|
|
func getPid() int {
|
|
return os.Getpid()
|
|
}
|