You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
844 B

  1. // +build !windows
  2. package utils
  3. import (
  4. "gin-vue-admin/global"
  5. zaprotatelogs "github.com/lestrrat-go/file-rotatelogs"
  6. "go.uber.org/zap/zapcore"
  7. "os"
  8. "path"
  9. "time"
  10. )
  11. //@author: [SliverHorn](https://github.com/SliverHorn)
  12. //@function: GetWriteSyncer
  13. //@description: zap logger中加入file-rotatelogs
  14. //@return: zapcore.WriteSyncer, error
  15. func GetWriteSyncer() (zapcore.WriteSyncer, error) {
  16. fileWriter, err := zaprotatelogs.New(
  17. path.Join(global.GVA_CONFIG.Zap.Director, "%Y-%m-%d.log"),
  18. zaprotatelogs.WithLinkName(global.GVA_CONFIG.Zap.LinkName),
  19. zaprotatelogs.WithMaxAge(7*24*time.Hour),
  20. zaprotatelogs.WithRotationTime(24*time.Hour),
  21. )
  22. if global.GVA_CONFIG.Zap.LogInConsole {
  23. return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(fileWriter)), err
  24. }
  25. return zapcore.AddSync(fileWriter), err
  26. }