From 3bb90d264f304ba41b177bdf4d86e41e4702cdff Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Mon, 23 Jul 2018 16:51:52 +0800 Subject: [PATCH] back to http request logging handler --- routers.go | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) 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 {