30 lines
667 B
Go
30 lines
667 B
Go
|
|
// +build !windows
|
||
|
|
|
||
|
|
package linuxMgr
|
||
|
|
|
||
|
|
import (
|
||
|
|
"os"
|
||
|
|
"path/filepath"
|
||
|
|
"syscall"
|
||
|
|
|
||
|
|
"goutil/fileUtil"
|
||
|
|
)
|
||
|
|
|
||
|
|
func init() {
|
||
|
|
//验证文件夹是否存在
|
||
|
|
fileAbsoluteDirectory := filepath.Join("Log")
|
||
|
|
if !fileUtil.IsDirExists(fileAbsoluteDirectory) {
|
||
|
|
if err := os.MkdirAll(fileAbsoluteDirectory, os.ModePerm|os.ModeTemporary); err != nil {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 标准输出
|
||
|
|
stdoutFile, _ := os.OpenFile("Log/Stdout.txt", os.O_WRONLY|os.O_CREATE|os.O_SYNC, 0644)
|
||
|
|
syscall.Dup2(int(stdoutFile.Fd()), 1)
|
||
|
|
|
||
|
|
// 标准错误输出
|
||
|
|
stderrFile, _ := os.OpenFile("Log/Stderr.txt", os.O_WRONLY|os.O_CREATE|os.O_SYNC|os.O_APPEND, 0644)
|
||
|
|
syscall.Dup2(int(stderrFile.Fd()), 2)
|
||
|
|
}
|