Skip to content

Commit

Permalink
Use stdlib logger to log signal handling so that it happens immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
komuw committed Feb 4, 2023
1 parent b74356e commit b9ed83a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"errors"
"fmt"
stdLog "log"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -260,7 +261,14 @@ func sigHandler(
defer cancel()

sigCaught := <-sigs
logger.Info("server got shutdown signal",

// TODO: to be fixed by: https://github.com/komuw/ong/issues/182
sl := stdLog.New(os.Stdout, "", 0)
if lHandler, ok := logger.Handler().(log.Handler); !ok {
sl = lHandler.StdLogger()
}

sl.Println("server got shutdown signal",
"signal", fmt.Sprintf("%v", sigCaught),
"shutdownDuration", drainDur.String(),
)
Expand Down

0 comments on commit b9ed83a

Please sign in to comment.