优化为json输出

This commit is contained in:
Yun
2024-02-03 01:57:56 +08:00
parent 1b61ac46e4
commit a08d268c92
4 changed files with 40 additions and 9 deletions
+3 -3
View File
@@ -17,13 +17,13 @@ func (l *Logger) nowFileName(event string) string {
if l.channel != "" {
timeDir = l.channel + "/" + timeDir
}
path := l.option.dir + "/" + timeDir + "_"+event + ".log"
path := l.option.dir + "/" + timeDir + "_" + event + ".log"
// fmt.Println(filepath.Abs(path))
return path
}
// 新建文件
func (l *Logger) getFile(event string,isRefresh bool) (*os.File, error) {
func (l *Logger) getFile(event string, isRefresh bool) (*os.File, error) {
f := l.loadFile(event)
if f != nil && !isRefresh {
return f, nil
@@ -38,7 +38,7 @@ func (l *Logger) getFile(event string,isRefresh bool) (*os.File, error) {
os.MkdirAll(dir, os.ModePerm) // 创建多层目录,如果存在不会报错
// 打开该文件,如果不存在则创建
file, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
file, err := os.OpenFile(fileName, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
// 打开失败,尝试创建
fmt.Println("打开日志文件失败")