From 01a976ab2f12859e92638f89469e11adc400cfd0 Mon Sep 17 00:00:00 2001 From: deranjer Date: Sat, 8 Dec 2018 21:58:29 -0500 Subject: [PATCH] updating logrus configurations --- config.toml | 4 ++-- engine/cronJobs.go | 7 ++----- main.go | 5 ++--- settings/settings.go | 16 ++++++++-------- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/config.toml b/config.toml index a1e216b9..ddbf1736 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.8" #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/cronJobs.go b/engine/cronJobs.go index c3927dc0..c58b5e9a 100644 --- a/engine/cronJobs.go +++ b/engine/cronJobs.go @@ -57,26 +57,23 @@ func CheckTorrentWatchFolder(c *cron.Cron, db *storm.DB, tclient *torrent.Client }) } -//CheckTorrents runs a upload ratio check, a queue check (essentially anything that should not be frontend dependent) +//CheckTorrentsCron runs a upload ratio check, a queue check (essentially anything that should not be frontend dependent) func CheckTorrentsCron(c *cron.Cron, db *storm.DB, tclient *torrent.Client, config Settings.FullClientSettings) { c.AddFunc("@every 30s", func() { Logger.Debug("Running a torrent Ratio and Queue Check") torrentLocalArray := Storage.FetchAllStoredTorrents(db) torrentQueues := Storage.FetchQueues(db) for _, singleTorrentFromStorage := range torrentLocalArray { - //torrentQueues := Storage.FetchQueues(db) var singleTorrent *torrent.Torrent for _, liveTorrent := range tclient.Torrents() { //matching the torrent from storage to the live torrent if singleTorrentFromStorage.Hash == liveTorrent.InfoHash().String() { singleTorrent = liveTorrent } } - //var TempHash metainfo.Hash - //calculatedTotalSize := CalculateDownloadSize(singleTorrentFromStorage, singleTorrent) calculatedCompletedSize := CalculateCompletedSize(singleTorrentFromStorage, singleTorrent) - //TempHash = singleTorrent.InfoHash() bytesCompleted := CalculateCompletedSize(singleTorrentFromStorage, singleTorrent) if float64(singleTorrentFromStorage.UploadedBytes)/float64(bytesCompleted) >= config.SeedRatioStop && singleTorrentFromStorage.TorrentUploadLimit == true { //If storage shows torrent stopped or if it is over the seeding ratio AND is under the global limit + Logger.WithFields(logrus.Fields{"Action: Stopping torrent due to seed Ratio": singleTorrentFromStorage.TorrentName}).Info() StopTorrent(singleTorrent, singleTorrentFromStorage, db) } if len(torrentQueues.ActiveTorrents) < config.MaxActiveTorrents && singleTorrentFromStorage.TorrentStatus == "Queued" { diff --git a/main.go b/main.go index c6e1e934..947a3dd8 100644 --- a/main.go +++ b/main.go @@ -33,7 +33,7 @@ var ( //Authenticated stores the value of the result of the client that connects to the server Authenticated = false APP_ID = os.Getenv("APP_ID") - sendJSON = make(chan interface{}) + sendJSON = make(chan interface{}) //channel for JSON messages ) var upgrader = websocket.Upgrader{ @@ -60,7 +60,6 @@ func handleMessages(conn *websocket.Conn) { func handleAuthentication(conn *websocket.Conn, db *storm.DB) { msg := Engine.Message{} err := conn.ReadJSON(&msg) - //conn.WriteJSON(msg) //TODO just for testing, remove payloadData, ok := msg.Payload.(map[string]interface{}) clientAuthToken, tokenOk := payloadData["ClientAuthString"].(string) fmt.Println("ClientAuthToken:", clientAuthToken, "TokenOkay", tokenOk, "PayloadData", payloadData, "PayloadData Okay?", ok) @@ -97,7 +96,7 @@ func handleAuthentication(conn *websocket.Conn, db *storm.DB) { fmt.Println("Claims", claims["ClientName"], claims["Issuer"]) Authenticated = true } else { - Logger.WithFields(logrus.Fields{"error": err}).Error("Authentication Error occured, cannot complete!") + Logger.WithFields(logrus.Fields{"error": err}).Error("Authentication Error occurred, cannot complete!") } } diff --git a/settings/settings.go b/settings/settings.go index 2eccc41e..f5a030dc 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -51,7 +51,7 @@ func defaultConfig() FullClientSettings { var Config FullClientSettings Config.ID = 4 //Unique ID for StormDB Config.Version = 1.0 - Config.LoggingLevel = 3 //Warn level + Config.LoggingLevel = logrus.WarnLevel //Warn level Config.TorrentConfig.DataDir = "downloads" //the absolute or relative path of the default download directory for torrents Config.TFileUploadFolder = "uploadedTorrents" Config.TorrentConfig.Seed = true @@ -129,19 +129,19 @@ func FullClientSettingsNew() FullClientSettings { logOutput := viper.GetString("serverConfig.LogOutput") switch logLevelString { //Options = Debug 5, Info 4, Warn 3, Error 2, Fatal 1, Panic 0 case "Panic": - logLevel = 0 + logLevel = logrus.PanicLevel case "Fatal": - logLevel = 1 + logLevel = logrus.FatalLevel case "Error": - logLevel = 2 + logLevel = logrus.ErrorLevel case "Warn": - logLevel = 3 + logLevel = logrus.WarnLevel case "Info": - logLevel = 4 + logLevel = logrus.InfoLevel case "Debug": - logLevel = 5 + logLevel = logrus.DebugLevel default: - logLevel = 3 + logLevel = logrus.WarnLevel } //HTTP, proxy