rotatelogs_windows.go 797 B

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