main_windows.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package main
  2. import (
  3. "github.com/gin-gonic/gin"
  4. rotatelogs "github.com/lestrrat-go/file-rotatelogs"
  5. "io"
  6. "miads/adslib"
  7. "miads/adslib/ads_redis"
  8. "os"
  9. "time"
  10. log "github.com/sirupsen/logrus"
  11. )
  12. func setupLogger(logName string, logLevel log.Level) {
  13. writer, err := rotatelogs.New(
  14. logName+".%Y%m%d",
  15. // WithLinkName为最新的日志建立软连接,以方便随着找到当前日志文件
  16. rotatelogs.WithLinkName(logName),
  17. // WithRotationTime设置日志分割的时间,这里设置为一小时分割一次
  18. rotatelogs.WithRotationTime(time.Hour),
  19. // WithMaxAge和WithRotationCount二者只能设置一个,
  20. // WithMaxAge设置文件清理前的最长保存时间,
  21. // WithRotationCount设置文件清理前最多保存的个数。
  22. rotatelogs.WithMaxAge(time.Hour*24*3),
  23. )
  24. if err != nil {
  25. log.Errorf("config local file system for logger error: %v", err)
  26. }
  27. log.SetReportCaller(true)
  28. log.SetLevel(logLevel)
  29. log.SetOutput(io.MultiWriter(writer, os.Stdout))
  30. }
  31. func setupRouter() *gin.Engine {
  32. r := gin.Default()
  33. r.POST("/ads", adsHandler)
  34. return r
  35. }
  36. func main() {
  37. ads_redis.Setup()
  38. adslib.GetConf()
  39. setupLogger(adslib.GetConf().LogPath+"/ads.log", log.TraceLevel)
  40. r := setupRouter()
  41. r.Run(":8080")
  42. }