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
797 B
28 lines
797 B
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
|
|
}
|