main.go 1.9 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.SetFormatter(&logrus.TextFormatter{
  24. ForceQuote: false,
  25. FullTimestamp: true,
  26. TimestampFormat: "2006-01-02 15:04:05",
  27. })
  28. if configs.ConfigGlobal.LogLevel < logrus.DebugLevel {
  29. pathMap := lfshook.LoggerMap{
  30. logrus.InfoLevel: &lumberjack.Logger{
  31. Filename: configs.ConfigGlobal.LogInfoPath,
  32. MaxSize: 10, // maxSize M
  33. MaxBackups: 5, // keep 5 file
  34. MaxAge: 7, // 7 day
  35. },
  36. logrus.ErrorLevel: &lumberjack.Logger{
  37. Filename: configs.ConfigGlobal.LogErrorPath,
  38. MaxSize: 10, // maxSize M
  39. MaxBackups: 5, // keep 5 file
  40. MaxAge: 7, // 7 day
  41. },
  42. }
  43. lfshook.NewLogger().Logger.Hooks.Add(lfshook.NewHook(
  44. pathMap,
  45. &logrus.TextFormatter{
  46. DisableColors: true,
  47. ForceQuote: true,
  48. TimestampFormat: "2006-01-02 15:04:05",
  49. PadLevelText: false,
  50. },
  51. ))
  52. lfshook.NewLogger().Logger.SetReportCaller(true)
  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. }