logging fixes

pull/1/head
Martin Boehm 2018-01-18 20:32:10 +01:00
parent 4e4c17a41a
commit 5ae73b9bb7
2 changed files with 10 additions and 10 deletions

View File

@ -146,17 +146,17 @@ func waitForSignalAndShutdown(s *server.HttpServer, timeout time.Duration) {
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
<-stop
sig := <-stop
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
log.Printf("\nShutdown with timeout: %s\n", timeout)
log.Printf("Shutdown %v", sig)
if err := s.Shutdown(ctx); err != nil {
log.Printf("Error: %v\n", err)
} else {
log.Println("Server stopped")
if s != nil {
if err := s.Shutdown(ctx); err != nil {
log.Printf("Error: %v", err)
}
}
}

View File

@ -4,7 +4,7 @@ import (
"blockbook/db"
"context"
"encoding/json"
"fmt"
"log"
"net/http"
"os"
@ -38,17 +38,17 @@ func New(db *db.RocksDB) (*HttpServer, error) {
}
func (s *HttpServer) Run() error {
fmt.Printf("http server starting on port %s", s.https.Addr)
log.Printf("http server starting on port %s", s.https.Addr)
return s.https.ListenAndServe()
}
func (s *HttpServer) Close() error {
fmt.Printf("http server closing")
log.Printf("http server closing")
return s.https.Close()
}
func (s *HttpServer) Shutdown(ctx context.Context) error {
fmt.Printf("http server shutdown")
log.Printf("http server shutdown")
return s.https.Shutdown(ctx)
}