12345678910111213141516171819202122232425262728 |
- package utils
- import (
- "os"
- "path"
- "time"
- "github.com/flipped-aurora/gin-vue-admin/server/global"
- zaprotatelogs "github.com/lestrrat-go/file-rotatelogs"
- "go.uber.org/zap/zapcore"
- )
- //@author: [SliverHorn](https://github.com/SliverHorn)
- //@function: GetWriteSyncer
- //@description: zap logger中加入file-rotatelogs
- //@return: zapcore.WriteSyncer, error
- func GetWriteSyncer() (zapcore.WriteSyncer, error) {
- fileWriter, err := zaprotatelogs.New(
- path.Join(global.GVA_CONFIG.Zap.Director, "%Y-%m-%d.log"),
- zaprotatelogs.WithMaxAge(7*24*time.Hour),
- zaprotatelogs.WithRotationTime(24*time.Hour),
- )
- if global.GVA_CONFIG.Zap.LogInConsole {
- return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(fileWriter)), err
- }
- return zapcore.AddSync(fileWriter), err
- }
|