logger.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package parser
  4. import (
  5. "fmt"
  6. "adm-gateway/config"
  7. "git.getensh.com/common/gopkgsv2/logger"
  8. "git.getensh.com/common/gopkgsv2/tasker"
  9. )
  10. var logConfig config.LogConfig
  11. func LoggerHandler(conf *config.Configure) {
  12. // logConfig.Path 不为空表示已经初始化
  13. if logConfig.Path != "" {
  14. if logConfig.Path == conf.Log.Path {
  15. return
  16. } else {
  17. // 刷盘
  18. // logger.Sync()
  19. }
  20. }
  21. // 取出Stacktrace和Level
  22. logStacktrace := conf.ADMGateway.LogStacktrace
  23. logLevel := conf.ADMGateway.LogLevel
  24. if logLevel == "" {
  25. logLevel = conf.Log.Level
  26. }
  27. // 新建全局日志器
  28. logger.New(conf.RunMode,
  29. logLevel,
  30. fmt.Sprintf("%s/%s.log", conf.Log.Path, conf.ADMGateway.ServiceName),
  31. conf.Log.MaxSize,
  32. conf.Log.MaxBackups,
  33. conf.Log.MaxAge,
  34. logStacktrace,
  35. true)
  36. // access日志器
  37. accessLogger := logger.New(conf.RunMode,
  38. logLevel,
  39. fmt.Sprintf("%s/%s-access.log", conf.Log.Path, conf.ADMGateway.ServiceName),
  40. conf.Log.MaxSize,
  41. conf.Log.MaxBackups,
  42. conf.Log.MaxAge,
  43. logStacktrace,
  44. false)
  45. // 设置访问日志
  46. tasker.SetLogger(accessLogger)
  47. logConfig = conf.Log
  48. }