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.

28 lines
908 B

  1. package utils
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/natefinch/lumberjack"
  5. "go.uber.org/zap/zapcore"
  6. "os"
  7. )
  8. //@author: [SliverHorn](https://github.com/SliverHorn)
  9. //@function: GetWriteSyncer
  10. //@description: zap logger中加入file-rotatelogs
  11. //@return: zapcore.WriteSyncer, error
  12. func GetWriteSyncer(file string) zapcore.WriteSyncer {
  13. lumberJackLogger := &lumberjack.Logger{
  14. Filename: file, //日志文件的位置
  15. MaxSize: 10, //在进行切割之前,日志文件的最大大小(以MB为单位)
  16. MaxBackups: 200, //保留旧文件的最大个数
  17. MaxAge: 30, //保留旧文件的最大天数
  18. Compress: true, //是否压缩/归档旧文件
  19. }
  20. if global.GVA_CONFIG.Zap.LogInConsole {
  21. return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(lumberJackLogger))
  22. }
  23. return zapcore.AddSync(lumberJackLogger)
  24. }