奇淼(piexlmax
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 55 additions and 94 deletions
-
1server/config.yaml
-
1server/config/zap.go
-
2server/core/server.go
-
54server/core/zap.go
-
1server/go.mod
-
28server/utils/rotatelogs.go
-
32server/utils/rotatelogs_unix.go
-
28server/utils/rotatelogs_windows.go
-
2web/src/core/gin-vue-admin.js
@ -0,0 +1,28 @@ |
|||
package utils |
|||
|
|||
import ( |
|||
"github.com/flipped-aurora/gin-vue-admin/server/global" |
|||
"github.com/natefinch/lumberjack" |
|||
"go.uber.org/zap/zapcore" |
|||
"os" |
|||
) |
|||
|
|||
//@author: [SliverHorn](https://github.com/SliverHorn)
|
|||
//@function: GetWriteSyncer
|
|||
//@description: zap logger中加入file-rotatelogs
|
|||
//@return: zapcore.WriteSyncer, error
|
|||
|
|||
func GetWriteSyncer(file string) zapcore.WriteSyncer { |
|||
lumberJackLogger := &lumberjack.Logger{ |
|||
Filename: file, //日志文件的位置
|
|||
MaxSize: 10, //在进行切割之前,日志文件的最大大小(以MB为单位)
|
|||
MaxBackups: 200, //保留旧文件的最大个数
|
|||
MaxAge: 30, //保留旧文件的最大天数
|
|||
Compress: true, //是否压缩/归档旧文件
|
|||
} |
|||
|
|||
if global.GVA_CONFIG.Zap.LogInConsole { |
|||
return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(lumberJackLogger)) |
|||
} |
|||
return zapcore.AddSync(lumberJackLogger) |
|||
} |
@ -1,32 +0,0 @@ |
|||
//go:build !windows
|
|||
// +build !windows
|
|||
|
|||
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.WithLinkName(global.GVA_CONFIG.Zap.LinkName), |
|||
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 |
|||
} |
@ -1,28 +0,0 @@ |
|||
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 |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue