SliverHorn
4 years ago
4 changed files with 52 additions and 19 deletions
-
2server/config.yaml
-
20server/core/zap.go
-
26server/utils/rotatelogs_unix.go
-
23server/utils/rotatelogs_windows.go
@ -0,0 +1,26 @@ |
|||
// +build !windows
|
|||
|
|||
package utils |
|||
|
|||
import ( |
|||
"gin-vue-admin/global" |
|||
zaprotatelogs "github.com/lestrrat-go/file-rotatelogs" |
|||
"go.uber.org/zap/zapcore" |
|||
"os" |
|||
"path" |
|||
"time" |
|||
) |
|||
|
|||
// GetWriteSyncer zap logger中加入file-rotatelogs
|
|||
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 |
|||
} |
@ -0,0 +1,23 @@ |
|||
package utils |
|||
|
|||
import ( |
|||
"gin-vue-admin/global" |
|||
zaprotatelogs "github.com/lestrrat-go/file-rotatelogs" |
|||
"go.uber.org/zap/zapcore" |
|||
"os" |
|||
"path" |
|||
"time" |
|||
) |
|||
|
|||
// GetWriteSyncer zap logger中加入file-rotatelogs
|
|||
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