v2: Logging! (#2831)

* logging: Initial implementation

* logging: More encoder formats, better defaults

* logging: Fix repetition bug with FilterEncoder; add more presets

* logging: DiscardWriter; delete or no-op logs that discard their output

* logging: Add http.handlers.log module; enhance Replacer methods

The Replacer interface has new methods to customize how to handle empty
or unrecognized placeholders. Closes #2815.

* logging: Overhaul HTTP logging, fix bugs, improve filtering, etc.

* logging: General cleanup, begin transitioning to using new loggers

* Fixes after merge conflict
This commit is contained in:
Matt Holt 2019-10-28 14:39:37 -06:00 committed by GitHub
parent 6c533558a3
commit b00dfd3965
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 2234 additions and 201 deletions

View file

@ -18,7 +18,6 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"log"
"net/http"
"sync"
"time"
@ -26,6 +25,7 @@ import (
"github.com/caddyserver/caddy/v2"
"github.com/go-acme/lego/v3/challenge"
"github.com/mholt/certmagic"
"go.uber.org/zap"
)
func init() {
@ -43,6 +43,7 @@ type TLS struct {
ctx caddy.Context
storageCleanTicker *time.Ticker
storageCleanStop chan struct{}
logger *zap.Logger
}
// CaddyModule returns the Caddy module information.
@ -56,6 +57,7 @@ func (TLS) CaddyModule() caddy.ModuleInfo {
// Provision sets up the configuration for the TLS app.
func (t *TLS) Provision(ctx caddy.Context) error {
t.ctx = ctx
t.logger = ctx.Logger(t)
// set up a new certificate cache; this (re)loads all certificates
cacheOpts := certmagic.CacheOptions{
@ -290,7 +292,7 @@ func (t *TLS) cleanStorageUnits() {
storageClean = time.Now()
log.Println("[INFO] tls: Cleaned up storage unit(s)")
t.logger.Info("cleaned up storage units")
}
// CertificateLoader is a type that can load certificates.