Skip to content

Commit

Permalink
修复zap 日志写入error invalid argument
Browse files Browse the repository at this point in the history
  • Loading branch information
fireinrain committed Mar 20, 2023
1 parent ca870cc commit aa6d018
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions log/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
var AsmrLog *zap.Logger
var LogFile *os.File

const logDir = "logs"
const logDir = "." + string(filepath.Separator) + "logs"

func init() {
// 创建一个控制台的 encoder
Expand All @@ -33,9 +33,12 @@ func init() {
}
//当前时间
now := time.Now()

// Format the time using the standard format string
currentTimeStr := now.Format("2006-01-02 15:04:05")
currentTimeStr := now.Format("2006-01-02-15:04:05")
//warn windows下文件名如果有空格会被截断导致文件无法识别
var filePath = logDir + string(filepath.Separator) + currentTimeStr + "-asmr.log"
filePath = filepath.ToSlash(filePath)
//提前创建日志文件
logFile, err := os.Create(filePath)
if err != nil {
Expand Down

0 comments on commit aa6d018

Please sign in to comment.