29 lines
683 B
Go
29 lines
683 B
Go
package core
|
|
|
|
import (
|
|
"fmt"
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap/zapcore"
|
|
"miniapp/core/internal"
|
|
"miniapp/global"
|
|
"miniapp/utils"
|
|
"os"
|
|
)
|
|
|
|
// Zap 获取 zap.Logger
|
|
// Author [SliverHorn](https://github.com/SliverHorn)
|
|
func Zap() (logger *zap.Logger) {
|
|
if ok, _ := utils.PathExists(global.GVA_CONFIG.Zap.Director); !ok { // 判断是否有Director文件夹
|
|
fmt.Printf("create %v directory\n", global.GVA_CONFIG.Zap.Director)
|
|
_ = os.Mkdir(global.GVA_CONFIG.Zap.Director, os.ModePerm)
|
|
}
|
|
|
|
cores := internal.Zap.GetZapCores()
|
|
logger = zap.New(zapcore.NewTee(cores...))
|
|
|
|
if global.GVA_CONFIG.Zap.ShowLine {
|
|
logger = logger.WithOptions(zap.AddCaller())
|
|
}
|
|
return logger
|
|
}
|