main.go 1.8 KB

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