tcp server 用于给andriod 客户端定时发送消息
liuxiaolong
2021-04-07 a5e6ddc46a0306f630ac53a8e0e3843bf8c17a05
log/log.go
@@ -2,6 +2,9 @@
import (
   "io/ioutil"
   "os"
   "os/exec"
   "path/filepath"
   "time"
   rotatelogs "github.com/lestrrat-go/file-rotatelogs"
@@ -30,8 +33,8 @@
   if Log != nil {
      return Log
   }
   infopath := "logs/info.log"
   rootPath := GetAppRootPath()
   infopath := rootPath + "/logs/info.log"
   infowriter, _ := rotatelogs.New(
      infopath+".%Y%m%d%H%M",
      rotatelogs.WithLinkName(infopath),
@@ -39,7 +42,7 @@
      rotatelogs.WithRotationTime(24*time.Hour),
   )
   errorpath := "logs/error.log"
   errorpath := rootPath + "/logs/error.log"
   errorwriter, _ := rotatelogs.New(
      errorpath+".%Y%m%d%H%M",
      rotatelogs.WithLinkName(errorpath),
@@ -58,3 +61,15 @@
   ))
   return Log
}
func GetAppRootPath() string {
   file,err:= exec.LookPath(os.Args[0])
   if err != nil {
      return ""
   }
   p, err := filepath.Abs(file)
   if err != nil {
      return ""
   }
   return filepath.Dir(p)
}