aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar alecdwm 2015-10-09 16:58:21 +1000
committerGravatar alecdwm 2015-10-09 16:58:21 +1000
commit461fcf886649c18b23cc3915c1c3de2072883b9e (patch)
treebf3d01479ecf9ad196d183472ae7c6a7b9c52618
parentbc443ae2caca5038d4b837c0be36a4ab00fecec4 (diff)
Added logrus functionality
-rw-r--r--lib/errors.go5
-rw-r--r--lib/gogetme.go12
-rw-r--r--main.go6
3 files changed, 12 insertions, 11 deletions
diff --git a/lib/errors.go b/lib/errors.go
index 118eba6..90969e2 100644
--- a/lib/errors.go
+++ b/lib/errors.go
@@ -16,11 +16,10 @@
package lib
-import "fmt"
+import log "github.com/Sirupsen/logrus"
func handleError(str string, err error) {
if err != nil {
- fmt.Println(err)
- panic("Error: " + str)
+ log.Fatal(str, " | ", err)
}
}
diff --git a/lib/gogetme.go b/lib/gogetme.go
index 89db20c..7fe379d 100644
--- a/lib/gogetme.go
+++ b/lib/gogetme.go
@@ -21,6 +21,8 @@ import (
"fmt"
"net/http"
"time"
+
+ log "github.com/Sirupsen/logrus"
)
type GitHubUserData struct {
@@ -75,10 +77,10 @@ func getGitHubUserData(username string) GitHubUserData {
func handler(w http.ResponseWriter, r *http.Request,
customUrl, githubUser string, githubUserData GitHubUserData) {
t := time.Now()
- fmt.Printf(
- "[%s] Handled connection from: %s\n",
- t.Format(time.RFC850),
- r.RemoteAddr)
+ log.WithFields(log.Fields{
+ "at": t.Format(time.RFC850),
+ "from": r.RemoteAddr,
+ }).Info("Handled Connection")
// Todo: detect whether project exists on GitHub or not,
// and forward through to GitHub user page if not
@@ -212,7 +214,7 @@ func Serve(customUrl, githubUser, listenPort string) {
})
// Listen and SERVE!
- fmt.Print("Handling connections:\n")
+ log.Info("Handling connections")
err := http.ListenAndServe(listenPort, nil)
handleError("Serving HTTP requests", err)
}
diff --git a/main.go b/main.go
index ff26f2d..047fc80 100644
--- a/main.go
+++ b/main.go
@@ -23,6 +23,7 @@ import (
"os"
"strings"
+ log "github.com/Sirupsen/logrus"
gogetme "go.owls.io/gogetme/lib"
)
@@ -32,13 +33,12 @@ func checkVarPromptUnset(promptVar *string, promptDesc string) {
input, err := bufio.NewReader(os.Stdin).ReadString('\n')
if err != nil {
- fmt.Println(err)
- panic("Error: Reading input string")
+ log.Fatal("Reading input string | ", err)
}
*promptVar = strings.Trim(input, "\n")
}
- fmt.Printf("%s set to '%s'\n", promptDesc, *promptVar)
+ log.Info(promptDesc, " set to '", *promptVar, "'")
}
func main() {