logger.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. "adm-vehicle-style/config"
  6. "fmt"
  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.Rpc.ADMVehicleStyle.LogStacktrace
  23. logLevel := conf.Rpc.ADMVehicleStyle.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.Rpc.ADMVehicleStyle.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.Rpc.ADMVehicleStyle.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. }