main.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package main
  2. import (
  3. "pbx-api-gin/internal/app"
  4. "pbx-api-gin/internal/pkg/configs"
  5. "pbx-api-gin/pkg/lfshook"
  6. "pbx-api-gin/pkg/utils"
  7. "github.com/gin-gonic/gin"
  8. "github.com/sirupsen/logrus"
  9. "gopkg.in/natefinch/lumberjack.v2"
  10. )
  11. var (
  12. gitCommitCode string
  13. buildDateTime string
  14. goVersion string
  15. )
  16. func main() {
  17. initVersion()
  18. // 解析配置文件
  19. configs.ConfigPath = "./configs/config.yaml"
  20. configs.DecodeConfig()
  21. configs.ConfigGlobal.LogLevel = logrus.InfoLevel
  22. gin.SetMode(gin.ReleaseMode)
  23. //gin.SetMode(gin.DebugMode)
  24. lfshook.NewLogger().Logger.SetReportCaller(true)
  25. lfshook.NewLogger().Logger.SetFormatter(&logrus.TextFormatter{
  26. ForceQuote: false,
  27. FullTimestamp: true,
  28. TimestampFormat: "2006-01-02 15:04:05",
  29. })
  30. if configs.ConfigGlobal.LogLevel < logrus.DebugLevel {
  31. pathMap := lfshook.LoggerMap{
  32. logrus.InfoLevel: &lumberjack.Logger{
  33. Filename: configs.ConfigGlobal.LogInfoPath,
  34. MaxSize: 10, // maxSize M
  35. MaxBackups: 5, // keep 5 file
  36. MaxAge: 7, // 7 day
  37. },
  38. logrus.ErrorLevel: &lumberjack.Logger{
  39. Filename: configs.ConfigGlobal.LogErrorPath,
  40. MaxSize: 10, // maxSize M
  41. MaxBackups: 5, // keep 5 file
  42. MaxAge: 7, // 7 day
  43. },
  44. }
  45. lfshook.NewLogger().Logger.Hooks.Add(lfshook.NewHook(
  46. pathMap,
  47. &logrus.TextFormatter{
  48. DisableColors: true,
  49. ForceQuote: true,
  50. TimestampFormat: "2006-01-02 15:04:05",
  51. },
  52. ))
  53. }
  54. app.StartApp()
  55. utils.Exit()
  56. //return nil
  57. }
  58. func initVersion() {
  59. if gitCommitCode != "" {
  60. //构建信息
  61. lfshook.NewLogger().Printf("git commit code: %s", gitCommitCode)
  62. lfshook.NewLogger().Printf("build date: %s", buildDateTime)
  63. lfshook.NewLogger().Printf("go version: %s", goVersion)
  64. utils.VersionInstance.BuildDate = buildDateTime
  65. utils.VersionInstance.GoVersion = goVersion
  66. utils.VersionInstance.GitCommitCode = gitCommitCode
  67. }
  68. }