main.go 1.9 KB

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