Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Commit

Permalink
webserver: move log.Init call to main
Browse files Browse the repository at this point in the history
One does not simply call a function that depends on config during
package initialization.
  • Loading branch information
Francisco Souza committed Mar 13, 2015
1 parent e497863 commit 18c76e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
4 changes: 0 additions & 4 deletions user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import (
"gopkg.in/mgo.v2/bson"
)

func init() {
log.Init()
}

var (
ErrUserAlreadyExists = errors.New("user already exists")
ErrUserNotFound = errors.New("user not found")
Expand Down
13 changes: 7 additions & 6 deletions webserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ package main
import (
"flag"
"fmt"
"log"
"net/http"

"github.com/codegangsta/negroni"
"github.com/tsuru/config"
"github.com/tsuru/gandalf/api"
"github.com/tsuru/tsuru/log"
)

const version = "0.6.0"
Expand All @@ -26,15 +26,16 @@ func main() {
fmt.Printf("gandalf-webserver version %s\n", version)
return
}
log.Printf("Opening config file: %s ...\n", *configFile)
log.Debugf("Opening config file: %s ...\n", *configFile)
err := config.ReadAndWatchConfigFile(*configFile)
if err != nil {
msg := `Could not open gandalf config file at %s (%s).
For an example, see: gandalf/etc/gandalf.conf
Note that you can specify a different config file with the --config option -- e.g.: --config=./etc/gandalf.conf`
log.Fatalf(msg, *configFile, err)
}
log.Printf("Successfully read config file: %s\n", *configFile)
log.Init()
log.Debugf("Successfully read config file: %s\n", *configFile)
router := api.SetupRouter()
n := negroni.New()
n.Use(api.NewLoggerMiddleware())
Expand All @@ -55,8 +56,8 @@ func main() {
if err != nil {
panic("You should configure a git:bare:location for gandalf.")
}
log.Printf("Repository location: %s\n", bareLocation)
log.Printf("gandalf-webserver %s listening on %s\n", version, bind)
log.Fatal(http.ListenAndServe(bind, router))
fmt.Printf("Repository location: %s\n", bareLocation)
fmt.Printf("gandalf-webserver %s listening on %s\n", version, bind)
http.ListenAndServe(bind, router)
}
}

0 comments on commit 18c76e7

Please sign in to comment.