Skip to content

Commit

Permalink
Further logging fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dkumor committed May 15, 2015
1 parent 031a34a commit 950a0dc
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 31 deletions.
5 changes: 2 additions & 3 deletions src/core/connectordb.go
Expand Up @@ -171,9 +171,8 @@ func startDatabase(dbPath string) error {
if err == util.ErrAlreadyRunning && !*forceStart {
fmt.Println("Use -force to force start the database even with connectordb.pid in there.")
return err
} else {
return err
}
return err
}

if err := dbmaker.Init(config.GetConfiguration()); err != nil {
Expand All @@ -197,7 +196,7 @@ func stopDatabase(dbPath string) error {
}

if err := dbmaker.Stop(config.GetConfiguration()); err != nil {
log.Printf("%v", err.Error())
log.Errorf("%v", err.Error())
}

return nil
Expand Down
9 changes: 5 additions & 4 deletions src/plugins/webclient/streamweb.go
@@ -1,10 +1,11 @@
package webclient

import (
log "github.com/Sirupsen/logrus"
"net/http"
"strconv"

log "github.com/Sirupsen/logrus"

"github.com/gorilla/mux"
)

Expand Down Expand Up @@ -47,7 +48,7 @@ func editStreamAction(se *SessionEnvironment) {
err = se.Operator.UpdateStream(stream)

if err != nil {
log.Printf(err.Error())
log.Errorf(err.Error())
se.Session.AddFlash(err.Error())
} else {
se.Session.AddFlash("Created Device")
Expand All @@ -67,15 +68,15 @@ func createStreamAction(se *SessionEnvironment) {
device, err := se.Operator.ReadDeviceByID(int64(devid))

if err != nil {
log.Printf(err.Error())
log.Errorf(err.Error())
se.Session.AddFlash("Error getting device, maybe it was deleted?")
goto redirect
}

err = se.Operator.CreateStreamByDeviceID(device.DeviceId, name, "x")

if err != nil {
log.Printf(err.Error())
log.Errorf(err.Error())
se.Session.AddFlash("Error creating stream.")
}

Expand Down
5 changes: 3 additions & 2 deletions src/plugins/webclient/userweb.go
@@ -1,16 +1,17 @@
package webclient

import (
log "github.com/Sirupsen/logrus"
"net/http"

log "github.com/Sirupsen/logrus"
)

func getUserPage(se *SessionEnvironment) {
log.Printf("getting user page")

pageData := make(map[string]interface{})

log.Printf("userdb: %p, user: %v\n", userdb, se.User)
log.Debugf("userdb: %p, user: %v", userdb, se.User)

devices, err := userdb.ReadAllDevicesByUserID(se.User.UserId)
pageData["devices"] = devices
Expand Down
39 changes: 20 additions & 19 deletions src/plugins/webclient/web.go
Expand Up @@ -3,12 +3,13 @@ package webclient
import (
"encoding/gob"
"html/template"
log "github.com/Sirupsen/logrus"
"net/http"
"path"
"streamdb"
"streamdb/users"

log "github.com/Sirupsen/logrus"

"github.com/gorilla/mux"
"github.com/kardianos/osext"
)
Expand Down Expand Up @@ -47,14 +48,14 @@ func authWrapper(h WebHandler) http.HandlerFunc {

log.Printf("Doing login\n")
se, err := NewSessionEnvironment(writer, request)
log.Printf("Created session\n")
log.Debugf("Created session\n")

if err != nil || se.User == nil || se.Device == nil {
log.Printf("Error: %v, %v\n", err, se)
log.Errorf("Error: %v, %v\n", err, se)
http.Redirect(writer, request, "/login/", http.StatusTemporaryRedirect)
return
}
log.Printf("Serving page\n")
log.Debugf("Serving page\n")

h(&se)
})
Expand All @@ -63,10 +64,10 @@ func authWrapper(h WebHandler) http.HandlerFunc {
// Display the login page
func getLogin(writer http.ResponseWriter, request *http.Request) {

log.Printf("Showing login page\n")
log.Printf("Showing login page")

se, err := NewSessionEnvironment(writer, request)
log.Printf("got session\n")
log.Debugf("got session")

// Don't log in somebody that's already logged in
if err == nil && se.User != nil && se.Device != nil {
Expand All @@ -84,7 +85,7 @@ func getLogin(writer http.ResponseWriter, request *http.Request) {

// Display the login page
func getLogout(writer http.ResponseWriter, request *http.Request) {
log.Printf("logout\n")
log.Printf("logout")

se, _ := NewSessionEnvironment(writer, request)
se.Logoff()
Expand All @@ -98,7 +99,7 @@ func postLogin(writer http.ResponseWriter, request *http.Request) {
userstr := request.PostFormValue("username")
passstr := request.PostFormValue("password")

log.Printf("Log in attempt: %v\n", userstr)
log.Printf("Log in attempt: %v", userstr)

usroperator, err := userdb.LoginOperator(userstr, passstr)
if err != nil {
Expand Down Expand Up @@ -126,28 +127,28 @@ func postLogin(writer http.ResponseWriter, request *http.Request) {
func init() {
folderPath, _ := osext.ExecutableFolder()
templatesPath := path.Join(folderPath, "templates")
basePath := path.Join(templatesPath, "base.html")
basePath := path.Join(templatesPath, "base.html")

// Parses our templates relative to the template path including the base
// everything needs
tMust := func(templateName string) *template.Template {
tPath := path.Join(templatesPath, templateName)
return template.Must(template.ParseFiles(tPath, basePath))
};

userEditTemplate = tMust("user_edit.html")
loginHomeTemplate = tMust("root.html")
deviceInfoTemplate = tMust("device_info.html")
firstrunTemplate = tMust("firstrun.html")
addUserTemplate = tMust("newuser.html")
loginPageTemplate = tMust("login.html")
return template.Must(template.ParseFiles(tPath, basePath))
}

userEditTemplate = tMust("user_edit.html")
loginHomeTemplate = tMust("root.html")
deviceInfoTemplate = tMust("device_info.html")
firstrunTemplate = tMust("firstrun.html")
addUserTemplate = tMust("newuser.html")
loginPageTemplate = tMust("login.html")
}

func Setup(subroutePrefix *mux.Router, udb *streamdb.Database) {
userdb = udb
folderPath, _ := osext.ExecutableFolder()
includepath := path.Join(folderPath, "static")
log.Printf("Include path set to: %v", includepath)
log.Debugf("Include path set to: %v", includepath)
subroutePrefix.PathPrefix("/inc/").Handler(http.StripPrefix("/inc/", http.FileServer(http.Dir(includepath))))

subroutePrefix.HandleFunc("/login/", http.HandlerFunc(getLogin))
Expand Down
2 changes: 1 addition & 1 deletion src/streamdb/dbmaker/gnatsd.go
Expand Up @@ -65,7 +65,7 @@ func (srv *GnatsdService) Start() error {
return nil
}
if srv.Stat != StatusInit {
log.Printf("Could not start gnatsd, status is %v", srv.Stat)
log.Errorf("Could not start gnatsd, status is %v", srv.Stat)
return ErrNotInitialized
}

Expand Down
2 changes: 1 addition & 1 deletion src/streamdb/dbmaker/postgres.go
Expand Up @@ -106,7 +106,7 @@ func (srv *PostgresService) Start() error {
return nil
}
if srv.Stat != StatusInit {
log.Printf("Could not start postgres, status is %v", srv.Stat)
log.Errorf("Could not start postgres, status is %v", srv.Stat)
return ErrNotInitialized
}
srv.Stat = StatusRunning
Expand Down
2 changes: 1 addition & 1 deletion src/streamdb/dbmaker/redis.go
Expand Up @@ -63,7 +63,7 @@ func (srv *RedisService) Start() error {
return nil
}
if srv.Stat != StatusInit {
log.Printf("Could not start redis, status is %v", srv.Stat)
log.Errorf("Could not start redis, status is %v", srv.Stat)
return ErrNotInitialized
}

Expand Down

0 comments on commit 950a0dc

Please sign in to comment.