Move ACME logger setup to cmd/tlstunnel

This will allow us to customize the logger options depending on CLI
flags.
This commit is contained in:
Simon Ser 2020-10-28 12:09:11 +01:00
parent 55fdebc9b7
commit 4684feb935
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 17 additions and 17 deletions

View File

@ -7,6 +7,7 @@ import (
"git.sr.ht/~emersion/go-scfg" "git.sr.ht/~emersion/go-scfg"
"git.sr.ht/~emersion/tlstunnel" "git.sr.ht/~emersion/tlstunnel"
"github.com/caddyserver/certmagic" "github.com/caddyserver/certmagic"
"go.uber.org/zap"
) )
var ( var (
@ -25,6 +26,22 @@ func main() {
srv := tlstunnel.NewServer() 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 != "" { if certDataPath != "" {
srv.ACMEConfig.Storage = &certmagic.FileStorage{Path: certDataPath} srv.ACMEConfig.Storage = &certmagic.FileStorage{Path: certDataPath}
} }

View File

@ -13,7 +13,6 @@ import (
"github.com/caddyserver/certmagic" "github.com/caddyserver/certmagic"
"github.com/pires/go-proxyproto" "github.com/pires/go-proxyproto"
"github.com/pires/go-proxyproto/tlvparse" "github.com/pires/go-proxyproto/tlvparse"
"go.uber.org/zap"
) )
type Server struct { type Server struct {
@ -37,22 +36,6 @@ func NewServer() *Server {
cfg.Issuer = mgr cfg.Issuer = mgr
cfg.Revoker = 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{ return &Server{
Listeners: make(map[string]*Listener), Listeners: make(map[string]*Listener),
ACMEManager: mgr, ACMEManager: mgr,