diff --git a/routers.go b/routers.go index 2241404..53ce20e 100644 --- a/routers.go +++ b/routers.go @@ -16,6 +16,7 @@ import ( "github.com/fangdingjun/gnutls" auth "github.com/fangdingjun/go-http-auth" "github.com/fangdingjun/gofast" + loghandler "github.com/gorilla/handlers" "github.com/gorilla/mux" ) @@ -32,19 +33,17 @@ func (lw *logwriter) Write(buf []byte) (int, error) { func initRouters(cfg conf) { - //logout := os.Stdout - /* - if logfile != "" { - fp, err := os.OpenFile(logfile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644) - if err != nil { - log.Println(err) - } else { - logout = fp - } + logout := os.Stdout + if logfile != "" { + fp, err := os.OpenFile(logfile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644) + if err != nil { + log.Println(err) + } else { + logout = fp } - */ + } - //w := &logwriter{logout, new(sync.Mutex)} + w := &logwriter{logout, new(sync.Mutex)} for _, l := range cfg { router := mux.NewRouter() @@ -137,8 +136,8 @@ func initRouters(cfg conf) { log.Fatal(err) } - //handler := loghandler.CombinedLoggingHandler(w, hdlr) - handler := hdlr + handler := loghandler.CombinedLoggingHandler(w, hdlr) + //handler := hdlr log.Printf("listen https on %s", addr) go func() { defer listener.Close() @@ -154,8 +153,8 @@ func initRouters(cfg conf) { } else { log.Printf("listen http on %s", addr) - //handler := loghandler.CombinedLoggingHandler(w, hdlr), - handler := hdlr + handler := loghandler.CombinedLoggingHandler(w, hdlr) + //handler := hdlr if err := http.ListenAndServe( addr, handler, ); err != nil {