Fix log.Reopen() functionality

This commit is contained in:
Dolf Schimmel
2016-12-30 09:08:13 +01:00
parent 419d418537
commit b0d7d8cf87

View File

@@ -14,7 +14,7 @@ type Logger struct {
var ( var (
Log *Logger Log *Logger
logFile string path string
) )
func Open(name, logLevelStr string) *Logger { func Open(name, logLevelStr string) *Logger {
@@ -42,20 +42,20 @@ func Open(name, logLevelStr string) *Logger {
return Log return Log
} }
func Reopen() {
func Reopen(args string) { if path == "" {
if logFile == "" {
Log.Notice("Asked to reopen logs but running in foreground. Ignoring.") Log.Notice("Asked to reopen logs but running in foreground. Ignoring.")
return return
} }
Log.Notice("Reopening log file per IPC request...") Log.Notice("Reopening log file per IPC request...")
LogRedirectStdOutToFile(logFile) LogRedirectStdOutToFile(path)
Log.Notice("Reopened log file per IPC request") Log.Notice("Reopened log file per IPC request")
} }
// If there are any existing fd's (e.g. we're reopening logs), we rely // If there are any existing fd's (e.g. we're reopening logs), we rely
// on garbage collection to clean them up for us. // on garbage collection to clean them up for us.
func LogRedirectStdOutToFile(logPath string) { func LogRedirectStdOutToFile(logPath string) {
path = logPath
if logPath == "" { if logPath == "" {
Log.Fatal("Log Path not set") Log.Fatal("Log Path not set")
} }