新增日志文件创建
This commit is contained in:
parent
531962b50f
commit
1312392a8f
@ -1,12 +1,12 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"hospital-admin-api/config"
|
||||
"hospital-admin-api/global"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Logrus 日志记录到文件
|
||||
@ -14,10 +14,19 @@ func Logrus() *logrus.Logger {
|
||||
// 日志文件
|
||||
fileName := path.Join(config.C.Log.FilePath, config.C.Log.FileName)
|
||||
|
||||
// 获取文件夹路径
|
||||
dirPath := filepath.Dir(fileName)
|
||||
|
||||
// 创建文件夹(如果不存在)
|
||||
err := os.MkdirAll(dirPath, os.ModePerm)
|
||||
if err != nil {
|
||||
panic("初始化日志文件失败")
|
||||
}
|
||||
|
||||
// 写入文件
|
||||
src, err := os.OpenFile(fileName, os.O_CREATE|os.O_APPEND|os.O_RDWR, os.ModePerm)
|
||||
if err != nil {
|
||||
fmt.Println("err", err)
|
||||
panic("初始化日志文件失败")
|
||||
}
|
||||
|
||||
global.Logger = logrus.New()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user