From 42e62717498c5c5ce3a0e757984096f9f8a28e6b Mon Sep 17 00:00:00 2001 From: John Date: Sun, 16 Sep 2018 16:38:17 +0800 Subject: [PATCH] =?UTF-8?q?glog.Cat=E5=BD=93=E7=9B=AE=E5=BD=95=E4=B8=8D?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E6=97=B6=E8=87=AA=E5=8A=A8=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/os/glog/glog_logger.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/g/os/glog/glog_logger.go b/g/os/glog/glog_logger.go index 70cbbc467..2d764f8eb 100644 --- a/g/os/glog/glog_logger.go +++ b/g/os/glog/glog_logger.go @@ -114,18 +114,13 @@ func (l *Logger) getFilePointer() *os.File { // 设置日志文件的存储目录路径 func (l *Logger) SetPath(path string) error { - //// 检测目录权限 - //if !gfile.Exists(path) { - // if err := gfile.Mkdir(path); err != nil { - // fmt.Fprintln(os.Stderr, fmt.Sprintf(`glog mkdir "%s" failed: %s`, path, err.Error())) - // return err - // } - //} - //if !gfile.IsWritable(path) { - // errstr := path + " is no writable for current user" - // fmt.Fprintln(os.Stderr, errstr) - // return errors.New(errstr) - //} + // 如果目录不存在,则递归创建 + if !gfile.Exists(path) { + if err := gfile.Mkdir(path); err != nil { + fmt.Fprintln(os.Stderr, fmt.Sprintf(`glog mkdir "%s" failed: %s`, path, err.Error())) + return err + } + } l.path.Set(strings.TrimRight(path, gfile.Separator)) return nil }