use single function that does platform specific things
This commit is contained in:
14
log/log.go
14
log/log.go
@@ -51,4 +51,18 @@ func Reopen() {
|
||||
Log.Notice("Reopened log file per IPC request")
|
||||
}
|
||||
|
||||
// If there are any existing fd's (e.g. we're reopening logs), we rely
|
||||
// on garbage collection to clean them up for us.
|
||||
func LogRedirectStdOutToFile(logPath string) {
|
||||
path = logPath
|
||||
if logPath == "" {
|
||||
Log.Fatal("Log Path not set")
|
||||
}
|
||||
|
||||
logFile, err := os.OpenFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
Log.Fatal(err)
|
||||
}
|
||||
|
||||
stdFdToLogFile(int(logFile.Fd()))
|
||||
}
|
||||
|
||||
@@ -2,24 +2,9 @@
|
||||
|
||||
package log
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
import "syscall"
|
||||
|
||||
// If there are any existing fd's (e.g. we're reopening logs), we rely
|
||||
// on garbage collection to clean them up for us.
|
||||
func LogRedirectStdOutToFile(logPath string) {
|
||||
path = logPath
|
||||
if logPath == "" {
|
||||
Log.Fatal("Log Path not set")
|
||||
}
|
||||
|
||||
logFile, err := os.OpenFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
Log.Fatal(err)
|
||||
}
|
||||
|
||||
syscall.Dup2(int(logFile.Fd()), 1)
|
||||
syscall.Dup2(int(logFile.Fd()), 2)
|
||||
func stdFdToLogFile(logFileFd int) {
|
||||
syscall.Dup2(logFileFd, 1)
|
||||
syscall.Dup2(logFileFd, 2)
|
||||
}
|
||||
@@ -1,23 +1,8 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
import "syscall"
|
||||
|
||||
// If there are any existing fd's (e.g. we're reopening logs), we rely
|
||||
// on garbage collection to clean them up for us.
|
||||
func LogRedirectStdOutToFile(logPath string) {
|
||||
path = logPath
|
||||
if logPath == "" {
|
||||
Log.Fatal("Log Path not set")
|
||||
}
|
||||
|
||||
logFile, err := os.OpenFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
Log.Fatal(err)
|
||||
}
|
||||
|
||||
syscall.Dup3(int(logFile.Fd()), 1, 0)
|
||||
syscall.Dup3(int(logFile.Fd()), 2, 0)
|
||||
func stdFdToLogFile(logFileFd int) {
|
||||
syscall.Dup3(logFileFd, 1, 0)
|
||||
syscall.Dup3(logFileFd, 2, 0)
|
||||
}
|
||||
Reference in New Issue
Block a user