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.

25 lines
724 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. // GetWriteSyncer zap logger中加入file-rotatelogs
  12. func GetWriteSyncer() (zapcore.WriteSyncer, error) {
  13. fileWriter, err := zaprotatelogs.New(
  14. path.Join(global.GVA_CONFIG.Zap.Director, "%Y-%m-%d.log"),
  15. zaprotatelogs.WithLinkName(global.GVA_CONFIG.Zap.LinkName),
  16. zaprotatelogs.WithMaxAge(7*24*time.Hour),
  17. zaprotatelogs.WithRotationTime(24*time.Hour),
  18. )
  19. if global.GVA_CONFIG.Zap.LogInConsole {
  20. return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(fileWriter)), err
  21. }
  22. return zapcore.AddSync(fileWriter), err
  23. }