1
0
mirror of https://github.com/astaxie/beego.git synced 2024-06-18 11:34:13 +00:00

auto create log dir

This commit is contained in:
chenkaihui 2018-04-04 15:59:52 +08:00
parent f16688817a
commit 6db9ad7002

View File

@ -21,6 +21,7 @@ import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"strconv"
"strings"
@ -161,6 +162,10 @@ func (w *fileLogWriter) createLogFile() (*os.File, error) {
if err != nil {
return nil, err
}
filepath := path.Dir(w.Filename)
os.MkdirAll(filepath, os.FileMode(perm))
fd, err := os.OpenFile(w.Filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.FileMode(perm))
if err == nil {
// Make sure file perm is user set perm cause of `os.OpenFile` will obey umask