From c55f09781991864e4263b5e09befcbcdb36bc73d Mon Sep 17 00:00:00 2001 From: MacBookAirM2 Date: Wed, 10 May 2023 12:47:46 +0800 Subject: [PATCH] add log storage --- conf/zinx.json | 12 ------------ zutils/witer.go | 7 ++++++- 2 files changed, 6 insertions(+), 13 deletions(-) delete mode 100644 conf/zinx.json diff --git a/conf/zinx.json b/conf/zinx.json deleted file mode 100644 index ba5d9779..00000000 --- a/conf/zinx.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "Name":"zinx v-0.10 demoApp", - "Host":"0.0.0.0", - "TCPPort":9090, - "MaxConn":3, - "WorkerPoolSize":10, - "LogDir": "./mylog", - "LogFile":"app.log", - "LogSaveDays":15, - "LogCons": true, - "LogIsolationLevel":0 -} \ No newline at end of file diff --git a/zutils/witer.go b/zutils/witer.go index 6a83bb7c..14327aaa 100644 --- a/zutils/witer.go +++ b/zutils/witer.go @@ -3,6 +3,7 @@ package zutils import ( "bufio" "bytes" + "fmt" "io" "os" "path/filepath" @@ -52,7 +53,11 @@ func New(path string) *Writer { } w.maxSize = sizeMiB * defMaxSize w.maxAge = defMaxAge - os.MkdirAll(filepath.Dir(w.fpath), 0755) + err := os.MkdirAll(filepath.Dir(w.fpath), 0755) + if err != nil { + fmt.Printf("%c[%d;%d;%dm%s%c[0m", 0x1B, 0, 40, 31, fmt.Sprintf("create log file error %-v", err), 0x1B) + return nil + } go w.daemon() return w }