logging fixes
This commit is contained in:
parent
4e4c17a41a
commit
5ae73b9bb7
12
blockbook.go
12
blockbook.go
@ -146,17 +146,17 @@ func waitForSignalAndShutdown(s *server.HttpServer, timeout time.Duration) {
|
|||||||
|
|
||||||
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
|
||||||
<-stop
|
sig := <-stop
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
log.Printf("\nShutdown with timeout: %s\n", timeout)
|
log.Printf("Shutdown %v", sig)
|
||||||
|
|
||||||
if err := s.Shutdown(ctx); err != nil {
|
if s != nil {
|
||||||
log.Printf("Error: %v\n", err)
|
if err := s.Shutdown(ctx); err != nil {
|
||||||
} else {
|
log.Printf("Error: %v", err)
|
||||||
log.Println("Server stopped")
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import (
|
|||||||
"blockbook/db"
|
"blockbook/db"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@ -38,17 +38,17 @@ func New(db *db.RocksDB) (*HttpServer, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *HttpServer) Run() 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()
|
return s.https.ListenAndServe()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *HttpServer) Close() error {
|
func (s *HttpServer) Close() error {
|
||||||
fmt.Printf("http server closing")
|
log.Printf("http server closing")
|
||||||
return s.https.Close()
|
return s.https.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *HttpServer) Shutdown(ctx context.Context) error {
|
func (s *HttpServer) Shutdown(ctx context.Context) error {
|
||||||
fmt.Printf("http server shutdown")
|
log.Printf("http server shutdown")
|
||||||
return s.https.Shutdown(ctx)
|
return s.https.Shutdown(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user