Skip to content

Commit 2f956c8

Browse files
committed
Improve error logging
1 parent 2e3ffb2 commit 2f956c8

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

cmd/erised/main.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"errors"
56
"flag"
67
"github.com/rs/zerolog"
@@ -32,7 +33,7 @@ func main() {
3233
profile := flag.String("profile", "", "profile this session. A valid file name is required")
3334
readTimeout := flag.Int("read", 5, "maximum duration in seconds for reading the entire request")
3435
searchPath := flag.String("path", "", "path to search recursively for X-Erised-Response-File")
35-
useTLS := flag.Bool("https", false, "use HTTPS instead of HTTP. A valid certificate and key are required")
36+
useTLS := flag.Bool("https", false, "use HTTPS instead of HTTP. A valid X.509 certificate and private key are required")
3637
writeTimeout := flag.Int("write", 10, "maximum duration in seconds before timing out response writes")
3738
setupFlags(flag.CommandLine)
3839
flag.Parse()
@@ -104,15 +105,15 @@ func main() {
104105
go func() {
105106
if *useTLS {
106107
if err = srv.cfg.ListenAndServeTLS(*certFile, *keyFile); !errors.Is(err, http.ErrServerClosed) {
107-
log.Error().Msg(err.Error())
108+
log.Error().Msg("Server shutdown error: " + err.Error())
108109
if err = syscall.Kill(syscall.Getpid(), syscall.SIGINT); err != nil {
109110
log.Fatal().Msg(err.Error())
110111
os.Exit(1)
111112
}
112113
}
113114
} else {
114115
if err = srv.cfg.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
115-
log.Error().Msg(err.Error())
116+
log.Error().Msg("Server shutdown error: " + err.Error())
116117
if err = syscall.Kill(syscall.Getpid(), syscall.SIGINT); err != nil {
117118
log.Fatal().Msg(err.Error())
118119
os.Exit(1)
@@ -123,14 +124,14 @@ func main() {
123124

124125
select {
125126
case <-srv.ctx.Done():
126-
if err = srv.cfg.Shutdown(srv.ctx); err != nil {
127-
log.Error().Msg(err.Error())
127+
if err = srv.cfg.Shutdown(srv.ctx); !errors.Is(err, context.Canceled) && *useTLS {
128+
log.Error().Msg("Context shutdown error: " + err.Error())
128129
}
129130
}
130131

131132
log.Debug().Msg("leaving main")
132133

133134
defer func() {
134-
log.Info().Msg("erised server shutting down")
135+
log.Info().Msg("erised server terminated")
135136
}()
136137
}

0 commit comments

Comments
 (0)