Use custom logger in main.
This commit is contained in:
parent
732e81f5a4
commit
09b8393c8a
1 changed files with 17 additions and 12 deletions
|
|
@ -5,13 +5,14 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mikestefanello/pagoda/pkg/handlers"
|
|
||||||
"github.com/mikestefanello/pagoda/pkg/services"
|
|
||||||
"github.com/mikestefanello/pagoda/pkg/tasks"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|
||||||
|
"github.com/mikestefanello/pagoda/pkg/handlers"
|
||||||
|
"github.com/mikestefanello/pagoda/pkg/log"
|
||||||
|
"github.com/mikestefanello/pagoda/pkg/services"
|
||||||
|
"github.com/mikestefanello/pagoda/pkg/tasks"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -19,14 +20,12 @@ func main() {
|
||||||
c := services.NewContainer()
|
c := services.NewContainer()
|
||||||
defer func() {
|
defer func() {
|
||||||
// Gracefully shutdown all services.
|
// Gracefully shutdown all services.
|
||||||
if err := c.Shutdown(); err != nil {
|
fatal("shutdown failed", c.Shutdown())
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Build the router.
|
// Build the router.
|
||||||
if err := handlers.BuildRouter(c); err != nil {
|
if err := handlers.BuildRouter(c); err != nil {
|
||||||
log.Fatalf("failed to build the router: %v", err)
|
fatal("failed to build the router", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register all task queues.
|
// Register all task queues.
|
||||||
|
|
@ -47,9 +46,7 @@ func main() {
|
||||||
|
|
||||||
if c.Config.HTTP.TLS.Enabled {
|
if c.Config.HTTP.TLS.Enabled {
|
||||||
certs, err := tls.LoadX509KeyPair(c.Config.HTTP.TLS.Certificate, c.Config.HTTP.TLS.Key)
|
certs, err := tls.LoadX509KeyPair(c.Config.HTTP.TLS.Certificate, c.Config.HTTP.TLS.Key)
|
||||||
if err != nil {
|
fatal("cannot load TLS certificate", err)
|
||||||
log.Fatalf("cannot load TLS certificate: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
srv.TLSConfig = &tls.Config{
|
srv.TLSConfig = &tls.Config{
|
||||||
Certificates: []tls.Certificate{certs},
|
Certificates: []tls.Certificate{certs},
|
||||||
|
|
@ -57,7 +54,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.Web.StartServer(&srv); errors.Is(err, http.ErrServerClosed) {
|
if err := c.Web.StartServer(&srv); errors.Is(err, http.ErrServerClosed) {
|
||||||
log.Fatalf("shutting down the server: %v", err)
|
fatal("shutting down the server", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
@ -67,3 +64,11 @@ func main() {
|
||||||
signal.Notify(quit, os.Kill)
|
signal.Notify(quit, os.Kill)
|
||||||
<-quit
|
<-quit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fatal logs an error and terminates the application, if the error is not nil.
|
||||||
|
func fatal(msg string, err error) {
|
||||||
|
if err != nil {
|
||||||
|
log.Default().Error(msg, "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue