1
1
Fork 0
mirror of https://git.sr.ht/~emersion/tlstunnel synced 2024-04-28 08:55:00 +02:00

Silence connection errors by default

Often times the connection-level errors clutter the logs, for
instance with failed TLS handshakes or unknown hostname.
This commit is contained in:
Simon Ser 2023-01-26 11:43:59 +01:00
parent bb3c49e3b5
commit 3fd3471799
2 changed files with 9 additions and 2 deletions

View File

@ -17,6 +17,8 @@ import (
var (
configPath = "config"
certDataPath = ""
debug = false
)
func newServer() (*tlstunnel.Server, error) {
@ -26,6 +28,7 @@ func newServer() (*tlstunnel.Server, error) {
}
srv := tlstunnel.NewServer()
srv.Debug = debug
loggerCfg := zap.Config{
Level: zap.NewAtomicLevelAt(zap.InfoLevel),
@ -68,6 +71,7 @@ func bumpOpenedFileLimit() error {
func main() {
flag.StringVar(&configPath, "config", configPath, "path to configuration file")
flag.BoolVar(&debug, "debug", false, "enable debug logging")
flag.Parse()
if err := bumpOpenedFileLimit(); err != nil {

View File

@ -38,6 +38,7 @@ func newACMECache() *acmeCache {
type Server struct {
Listeners map[string]*Listener // indexed by listening address
Frontends []*Frontend
Debug bool
ManagedNames []string
UnmanagedCerts []tls.Certificate
@ -256,8 +257,10 @@ func (ln *Listener) serve() error {
}
go func() {
if err := ln.handle(conn); err != nil {
log.Printf("listener %q: %v", ln.Address, err)
err := ln.handle(conn)
srv := ln.atomic.Load().(*listenerHandles).Server
if err != nil && srv.Debug {
log.Printf("listener %q: connection %q: %v", ln.Address, conn.RemoteAddr(), err)
}
}()
}