From 4684feb935a8ca58f4eb96afb29ef23fb6ccc1c6 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 28 Oct 2020 12:09:11 +0100 Subject: [PATCH] Move ACME logger setup to cmd/tlstunnel This will allow us to customize the logger options depending on CLI flags. --- cmd/tlstunnel/main.go | 17 +++++++++++++++++ server.go | 17 ----------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/cmd/tlstunnel/main.go b/cmd/tlstunnel/main.go index 23a0a73..f4ba7ef 100644 --- a/cmd/tlstunnel/main.go +++ b/cmd/tlstunnel/main.go @@ -7,6 +7,7 @@ import ( "git.sr.ht/~emersion/go-scfg" "git.sr.ht/~emersion/tlstunnel" "github.com/caddyserver/certmagic" + "go.uber.org/zap" ) var ( @@ -25,6 +26,22 @@ func main() { srv := tlstunnel.NewServer() + loggerCfg := zap.Config{ + Level: zap.NewAtomicLevelAt(zap.InfoLevel), + Encoding: "console", + EncoderConfig: zap.NewDevelopmentEncoderConfig(), + OutputPaths: []string{"stderr"}, + ErrorOutputPaths: []string{"stderr"}, + DisableStacktrace: true, + DisableCaller: true, + } + logger, err := loggerCfg.Build() + if err != nil { + log.Fatalf("failed to initialize zap logger: %v", err) + } + srv.ACMEConfig.Logger = logger + srv.ACMEManager.Logger = logger + if certDataPath != "" { srv.ACMEConfig.Storage = &certmagic.FileStorage{Path: certDataPath} } diff --git a/server.go b/server.go index 7c42bd7..a1a1161 100644 --- a/server.go +++ b/server.go @@ -13,7 +13,6 @@ import ( "github.com/caddyserver/certmagic" "github.com/pires/go-proxyproto" "github.com/pires/go-proxyproto/tlvparse" - "go.uber.org/zap" ) type Server struct { @@ -37,22 +36,6 @@ func NewServer() *Server { cfg.Issuer = mgr cfg.Revoker = mgr - loggerCfg := zap.Config{ - Level: zap.NewAtomicLevelAt(zap.InfoLevel), - Encoding: "console", - EncoderConfig: zap.NewDevelopmentEncoderConfig(), - OutputPaths: []string{"stderr"}, - ErrorOutputPaths: []string{"stderr"}, - DisableStacktrace: true, - DisableCaller: true, - } - logger, err := loggerCfg.Build() - if err != nil { - log.Fatalf("failed to initialize zap logger: %v", err) - } - cfg.Logger = logger - mgr.Logger = logger - return &Server{ Listeners: make(map[string]*Listener), ACMEManager: mgr,