38 lines
998 B
Go
38 lines
998 B
Go
/*
|
|
* @Date: 2021-03-22 16:44:06
|
|
* @LastEditors: viletyy
|
|
* @LastEditTime: 2021-06-10 15:18:37
|
|
* @FilePath: /potato/pkg/rotatelogs_unix.go
|
|
*/
|
|
// +build !windows
|
|
|
|
package pkg
|
|
|
|
import (
|
|
"os"
|
|
"path"
|
|
"time"
|
|
|
|
zaprotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
|
"github.com/viletyy/potato/global"
|
|
"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.GO_CONFIG.Zap.Director, "%Y-%m-%d.log"),
|
|
zaprotatelogs.WithLinkName(global.GO_CONFIG.Zap.LinkName),
|
|
zaprotatelogs.WithMaxAge(7*24*time.Hour),
|
|
zaprotatelogs.WithRotationTime(24*time.Hour),
|
|
)
|
|
if global.GO_CONFIG.Zap.LogInConsole {
|
|
return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(fileWriter)), err
|
|
}
|
|
return zapcore.AddSync(fileWriter), err
|
|
}
|