Skip to content

Commit

Permalink
BREAKING: upgrade logr from v0.3.0 to v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
abursavich committed Aug 29, 2021
1 parent 4d0f296 commit 542222c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
3 changes: 0 additions & 3 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ import (
//
// Repeated TERM or INT signals will bypass any delay or grace time.
func Contexts(ctx context.Context, log logr.Logger, delay, grace time.Duration) (warn, soft, hard context.Context) {
if log == nil {
log = logr.Discard()
}
sigCh := make(chan os.Signal, 3)
signal.Notify(sigCh, syscall.SIGTERM, syscall.SIGINT)
hardCtx, hardCancel := context.WithCancel(ctx)
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module bursavich.dev/graceful

go 1.16
go 1.17

require (
github.com/go-logr/logr v0.3.0
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
github.com/go-logr/logr v1.1.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
github.com/go-logr/logr v0.3.0 h1:q4c+kbcR0d5rSurhBR8dIgieOaYpXtsdTYfx22Cu6rs=
github.com/go-logr/logr v0.3.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-logr/logr v1.1.0 h1:nAbevmWlS2Ic4m4+/An5NXkaGqlqpbBgdcuThZxnZyI=
github.com/go-logr/logr v1.1.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
15 changes: 9 additions & 6 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ type ServerConfig struct {

func (cfg *ServerConfig) init() {
cfg.initOnce.Do(func() {
if cfg.Logger == nil {
cfg.Logger = logr.Discard()
}
cfg.Logger = loggerOrDiscard(cfg.Logger)
cfg.warnCtx, cfg.warnCancel = context.WithCancel(context.TODO())
})
}
Expand Down Expand Up @@ -175,9 +173,7 @@ type DualServerConfig struct {

func (cfg *DualServerConfig) init() {
cfg.initOnce.Do(func() {
if cfg.Logger == nil {
cfg.Logger = logr.Discard()
}
cfg.Logger = loggerOrDiscard(cfg.Logger)
cfg.warnCtx, cfg.warnCancel = context.WithCancel(context.TODO())
})
}
Expand Down Expand Up @@ -272,3 +268,10 @@ func (cfg *DualServerConfig) Serve(ctx context.Context, intLis, extLis net.Liste
// Wait for shutdown.
return g.Wait()
}

func loggerOrDiscard(log logr.Logger) logr.Logger {
if log.GetSink() == nil {
return logr.Discard()
}
return log
}

0 comments on commit 542222c

Please sign in to comment.