mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 08:32:40 +08:00
fix log output
This commit is contained in:
13
fs/fs.go
13
fs/fs.go
@ -1,7 +1,9 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func IsExist(path string) bool {
|
||||
@ -17,3 +19,14 @@ func IsDir(path string) bool {
|
||||
|
||||
return file.IsDir()
|
||||
}
|
||||
|
||||
// 打开或新建文件,目录不存在时创建目录
|
||||
func OpenOrNew(filename string) (io.Writer, error) {
|
||||
dir := filepath.Dir(filename)
|
||||
if !IsExist(dir) {
|
||||
os.MkdirAll(dir, 0744)
|
||||
}
|
||||
|
||||
mode := os.FileMode(0644)
|
||||
return os.OpenFile(filename, os.O_CREATE|os.O_WRONLY|os.O_APPEND, mode)
|
||||
}
|
||||
|
7
fs/fs_test.go
Normal file
7
fs/fs_test.go
Normal file
@ -0,0 +1,7 @@
|
||||
package fs
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestOpenFile(t *testing.T) {
|
||||
OpenOrNew("logs/aaa.log")
|
||||
}
|
Reference in New Issue
Block a user