Use glog levelled logging to decrease announce overhead
This commit is contained in:
parent
df5ad919f9
commit
f3f58c024c
2 changed files with 21 additions and 17 deletions
22
http/http.go
22
http/http.go
|
@ -48,18 +48,21 @@ type ResponseHandler func(http.ResponseWriter, *http.Request, httprouter.Params)
|
|||
func makeHandler(handler ResponseHandler) httprouter.Handle {
|
||||
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
||||
start := time.Now()
|
||||
code, err := handler(w, r, p)
|
||||
|
||||
httpCode, err := handler(w, r, p)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), code)
|
||||
http.Error(w, err.Error(), httpCode)
|
||||
}
|
||||
|
||||
glog.Infof(
|
||||
"Completed %v %s %s in %v",
|
||||
code,
|
||||
http.StatusText(code),
|
||||
r.URL.Path,
|
||||
time.Since(start),
|
||||
)
|
||||
if glog.V(2) {
|
||||
glog.Infof(
|
||||
"Completed %v %s %s in %v",
|
||||
httpCode,
|
||||
http.StatusText(httpCode),
|
||||
r.URL.Path,
|
||||
time.Since(start),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,6 +99,7 @@ func Serve(cfg *config.Config) {
|
|||
glog.Fatal("New: ", err)
|
||||
}
|
||||
|
||||
glog.V(0).Info("Starting on ", cfg.Addr)
|
||||
graceful.Run(cfg.Addr, cfg.RequestTimeout.Duration, NewRouter(t, cfg))
|
||||
}
|
||||
|
||||
|
|
16
main.go
16
main.go
|
@ -38,36 +38,36 @@ func Boot() {
|
|||
flag.Parse()
|
||||
|
||||
runtime.GOMAXPROCS(maxprocs)
|
||||
glog.Info("set max threads to ", maxprocs)
|
||||
glog.V(1).Info("Set max threads to ", maxprocs)
|
||||
|
||||
if profile != "" {
|
||||
f, err := os.Create(profile)
|
||||
if err != nil {
|
||||
glog.Fatalf("failed to create profile file: %s\n", err)
|
||||
glog.Fatalf("Failed to create profile file: %s\n", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
pprof.StartCPUProfile(f)
|
||||
glog.Info("started profiling")
|
||||
glog.Info("Started profiling")
|
||||
|
||||
defer func() {
|
||||
pprof.StopCPUProfile()
|
||||
glog.Info("stopped profiling")
|
||||
glog.Info("Stopped profiling")
|
||||
}()
|
||||
}
|
||||
|
||||
cfg, err := config.Open(configPath)
|
||||
if err != nil {
|
||||
glog.Fatalf("failed to parse configuration file: %s\n", err)
|
||||
glog.Fatalf("Failed to parse configuration file: %s\n", err)
|
||||
}
|
||||
if cfg == &config.DefaultConfig {
|
||||
glog.Info("using default config")
|
||||
glog.V(1).Info("Using default config")
|
||||
} else {
|
||||
glog.Infof("loaded config file: %s", configPath)
|
||||
glog.V(1).Infof("Loaded config file: %s", configPath)
|
||||
}
|
||||
|
||||
http.Serve(cfg)
|
||||
glog.Info("gracefully shutdown")
|
||||
glog.Info("Gracefully shut down")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
Loading…
Reference in a new issue