main.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package main
  2. import (
  3. agiServer "pbx-api-gin/api"
  4. "pbx-api-gin/internal/app"
  5. "pbx-api-gin/internal/pkg/configs"
  6. "pbx-api-gin/pkg/lfshook"
  7. "pbx-api-gin/pkg/utils"
  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. go agiServer.StartAGI("127.0.0.1", "8090")
  19. // 解析配置文件
  20. configs.DecodeConfig()
  21. configs.ConfigGlobal.LogLevel = logrus.InfoLevel
  22. //gin.SetMode(gin.ReleaseMode)
  23. //gin.SetMode(gin.DebugMode)
  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. PadLevelText: false,
  51. },
  52. ))
  53. lfshook.NewLogger().Logger.SetReportCaller(true)
  54. }
  55. utils.InitLog()
  56. app.StartApp()
  57. utils.Exit()
  58. //return nil
  59. }
  60. func initVersion() {
  61. if gitCommitCode != "" {
  62. //构建信息
  63. //utils.Logger.Printf("software version: V10.01")
  64. lfshook.NewLogger().Printf("git commit code: %s", gitCommitCode)
  65. lfshook.NewLogger().Printf("build date: %s", buildDateTime)
  66. lfshook.NewLogger().Printf("go version: %s", goVersion)
  67. utils.VersionInstance.BuildDate = buildDateTime
  68. utils.VersionInstance.GoVersion = goVersion
  69. utils.VersionInstance.GitCommitCode = gitCommitCode
  70. }
  71. }