forked from lanhebe/proxypool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.go
40 lines (34 loc) · 737 Bytes
/
file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package log
import (
"os"
"path/filepath"
)
var (
logDir = "tmp"
logFilePath = filepath.Join(logDir, "run.log")
allLogFilePath = filepath.Join(logDir, "all.log")
)
var logFile *os.File
var allLogFile *os.File
func init() {
ok := initDir(logDir)
if ok {
logFile = initFile(logFilePath)
allLogFile = initFile(allLogFilePath)
}
}
func initDir(path string) bool {
if _, err := os.Stat(path); os.IsNotExist(err) {
if err := os.Mkdir(path, 0755); err != nil {
Errorln("init log dir error: %s", err.Error())
}
}
return true
}
func initFile(path string) *os.File {
f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0755)
if err != nil {
Errorln("get log file error: %s", err.Error())
}
return f
}