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.

22 lines
642 B

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