From eeb6e102f18c93960f6e3e3152c2065afa6f3405 Mon Sep 17 00:00:00 2001 From: deranjer Date: Sun, 25 Mar 2018 21:23:15 -0400 Subject: [PATCH] fixing log not writing to file --- config.toml | 4 ++-- engine/engine.go | 5 ++++- main.go | 19 ++++++++++--------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/config.toml b/config.toml index 418b12ca..96439e74 100644 --- a/config.toml +++ b/config.toml @@ -2,8 +2,8 @@ ServerPort = ":8000" #leave format as is it expects a string with colon ServerAddr = "192.168.1.6" #Put in the IP address you want to bind to - LogLevel = "Info" # Options = Debug, Info, Warn, Error, Fatal, Panic - LogOutput = "stdout" #Options = file, stdout #file will print it to logs/server.log + LogLevel = "Debug" # Options = Debug, Info, Warn, Error, Fatal, Panic + LogOutput = "file" #Options = file, stdout #file will print it to logs/server.log SeedRatioStop = 1.50 #automatically stops the torrent after it reaches this seeding ratio diff --git a/engine/engine.go b/engine/engine.go index 243705a5..fa963cf6 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -280,8 +280,11 @@ func CreateRunningTorrentArray(tclient *torrent.Client, TorrentLocalArray []*Sto Storage.UpdateStorageTick(db, tStorage) go func() { //moving torrent in separate go-routine then verifying that the data is still there and correct err := MoveAndLeaveSymlink(config, singleTorrent.InfoHash().String(), db, false, "") //can take some time to move file so running this in another thread TODO make this a goroutine and skip this block if the routine is still running - if err != nil { + if err != nil { //If we fail, print the error and attempt a retry + Logger.WithFields(logrus.Fields{"singleTorrent": singleTorrentFromStorage.TorrentName, "error": err}).Info("Failed to move Torrent!") VerifyData(singleTorrent) + tStorage.TorrentMoved = false + Storage.UpdateStorageTick(db, tStorage) } }() diff --git a/main.go b/main.go index d14dad18..0d00f86c 100644 --- a/main.go +++ b/main.go @@ -103,16 +103,17 @@ func main() { if err != nil { fmt.Println("Unable to create 'log' folder for logging.... please check permissions.. forcing output to stdout", err) Logger.Out = os.Stdout - } else { - os.Remove("logs/server.log") //cleanup the old log on every restart - file, err := os.OpenFile("logs/server.log", os.O_CREATE|os.O_WRONLY, 0755) //creating the log file - defer file.Close() //TODO.. since we write to this constantly how does close work? - if err != nil { - fmt.Println("Unable to create file for logging.... please check permissions.. forcing output to stdout") - Logger.Out = os.Stdout - } - Logger.Out = file } + } else { + os.Remove("logs/server.log") //cleanup the old log on every restart + file, err := os.OpenFile("logs/server.log", os.O_CREATE|os.O_WRONLY, 0755) //creating the log file + //defer file.Close() //TODO.. since we write to this constantly how does close work? + if err != nil { + fmt.Println("Unable to create file for logging.... please check permissions.. forcing output to stdout") + Logger.Out = os.Stdout + } + fmt.Println("Logging to file logs/server.log") + Logger.Out = file } } else { Logger.Out = os.Stdout