From 6b48322626d7677bdaccfceb6296ce87d707a341 Mon Sep 17 00:00:00 2001 From: Zorchenhimer Date: Sat, 30 Mar 2019 16:15:22 -0400 Subject: [PATCH] Use the logger Replace fmt.Print[f|ln]() with the logger equivalent. --- chatcommands.go | 10 +++++----- handlers.go | 21 ++++++++++----------- main.go | 4 ++-- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/chatcommands.go b/chatcommands.go index 22cb63e..87c2116 100644 --- a/chatcommands.go +++ b/chatcommands.go @@ -454,7 +454,7 @@ var commands = &CommandControl{ return "Unable to generate new pin: " + err.Error() } - fmt.Println("New room access pin: ", pin) + common.LogInfoln("New room access pin: ", pin) return "New access pin: " + pin }, }, @@ -470,7 +470,7 @@ var commands = &CommandControl{ switch AccessMode(strings.ToLower(args[0])) { case AccessOpen: settings.RoomAccess = AccessOpen - fmt.Println("[access] Room set to open") + common.LogInfoln("[access] Room set to open") return "Room access set to open" case AccessPin: @@ -482,17 +482,17 @@ var commands = &CommandControl{ } else { _, err := settings.generateNewPin() if err != nil { - fmt.Println("Error generating new access pin: ", err.Error()) + common.LogErrorln("Error generating new access pin: ", err.Error()) return "Unable to generate a new pin, access unchanged: " + err.Error() } } settings.RoomAccess = AccessPin - fmt.Println("[access] Room set to pin: " + settings.RoomAccessPin) + common.LogInfoln("[access] Room set to pin: " + settings.RoomAccessPin) return "Room access set to Pin: " + settings.RoomAccessPin case AccessRequest: settings.RoomAccess = AccessRequest - fmt.Println("[access] Room set to request") + common.LogInfoln("[access] Room set to request") return "Room access set to request. WARNING: this isn't implemented yet." default: diff --git a/handlers.go b/handlers.go index a53e89e..7d00de4 100644 --- a/handlers.go +++ b/handlers.go @@ -160,7 +160,7 @@ func checkRoomAccess(w http.ResponseWriter, r *http.Request) bool { session, err := sstore.Get(r, "moviesession") if err != nil { // Don't return as server error here, just make a new session. - fmt.Printf("Unable to get session for client %s: %v\n", r.RemoteAddr, err) + common.LogErrorf("Unable to get session for client %s: %v\n", r.RemoteAddr, err) } if settings.RoomAccess == AccessPin { @@ -171,12 +171,12 @@ func checkRoomAccess(w http.ResponseWriter, r *http.Request) bool { // Check for correct pin err = r.ParseForm() if err != nil { - fmt.Printf("Error parsing form") + common.LogErrorf("Error parsing form") http.Error(w, "Unable to get session data", http.StatusInternalServerError) } postPin := r.Form.Get("txtInput") - fmt.Printf("Received pin: %s\n", postPin) + common.LogDebugf("Received pin: %s\n", postPin) if postPin == settings.RoomAccessPin { // Pin is correct. Save it to session and return true. session.Values["pin"] = settings.RoomAccessPin @@ -220,7 +220,7 @@ func checkRoomAccess(w http.ResponseWriter, r *http.Request) bool { func handlePinTemplate(w http.ResponseWriter, r *http.Request, errorMessage string) { t, err := template.ParseFiles("./static/base.html", "./static/thedoor.html") if err != nil { - fmt.Printf("Error parsing template file: %v", err) + common.LogErrorf("Error parsing template file: %v", err) return } @@ -238,7 +238,7 @@ func handlePinTemplate(w http.ResponseWriter, r *http.Request, errorMessage stri err = t.Execute(w, data) if err != nil { - fmt.Printf("Error executing file, %v", err) + common.LogErrorf("Error executing file, %v", err) } } @@ -278,7 +278,7 @@ func handleHelpTemplate(w http.ResponseWriter, r *http.Request) { func handlePin(w http.ResponseWriter, r *http.Request) { session, err := sstore.Get(r, "moviesession") if err != nil { - fmt.Printf("Unable to get session: %v\n", err) + common.LogDebugf("Unable to get session: %v\n", err) } val := session.Values["pin"] @@ -289,21 +289,20 @@ func handlePin(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "unable to save session: %v", err) } fmt.Fprint(w, "Pin was not set") - fmt.Println("pin was not set") + common.LogDebugln("pin was not set") } else { fmt.Fprintf(w, "pin set: %v", val) - fmt.Printf("pin is set: %v\n", val) + common.LogDebugf("pin is set: %v\n", val) } } func handleIndexTemplate(w http.ResponseWriter, r *http.Request) { - fmt.Printf("RoomAcces: %s\n", settings.RoomAccess) if settings.RoomAccess != AccessOpen { if !checkRoomAccess(w, r) { - fmt.Println("Denied access") + common.LogDebugln("Denied access") return } - fmt.Println("Granted access") + common.LogDebugln("Granted access") } t, err := template.ParseFiles("./static/base.html", "./static/main.html") diff --git a/main.go b/main.go index a387715..40c7dd4 100644 --- a/main.go +++ b/main.go @@ -74,8 +74,8 @@ func main() { common.LogInfoln("Stream key: ", settings.GetStreamKey()) common.LogInfoln("Admin password: ", settings.AdminPassword) common.LogInfoln("Listen and serve ", addr) - fmt.Println("RoomAccess: ", settings.RoomAccess) - fmt.Println("RoomAccessPin: ", settings.RoomAccessPin) + common.LogInfoln("RoomAccess: ", settings.RoomAccess) + common.LogInfoln("RoomAccessPin: ", settings.RoomAccessPin) go startServer() go startRmtpServer()