summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-04-10 08:12:42 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2020-04-10 08:12:42 -0600
commit999ab22b8cbe3721eff6ae57526024a17f7cee4e (patch)
tree45c6fe8e4565a30bab2697860364b724f8346975 /modules
parent9991fdc4958de9601cbf37ddfd814733190a00d0 (diff)
caddyhttp: Add nil check (fixes #3248 and fixes #3250)
Diffstat (limited to 'modules')
-rw-r--r--modules/caddyhttp/fileserver/command.go2
-rw-r--r--modules/caddyhttp/server.go16
2 files changed, 13 insertions, 5 deletions
diff --git a/modules/caddyhttp/fileserver/command.go b/modules/caddyhttp/fileserver/command.go
index bd740e8..53aa7aa 100644
--- a/modules/caddyhttp/fileserver/command.go
+++ b/modules/caddyhttp/fileserver/command.go
@@ -85,7 +85,7 @@ func cmdFileServer(fs caddycmd.Flags) (int, error) {
if domain != "" {
route.MatcherSetsRaw = []caddy.ModuleMap{
- caddy.ModuleMap{
+ {
"host": caddyconfig.JSON(caddyhttp.MatchHost{domain}, nil),
},
}
diff --git a/modules/caddyhttp/server.go b/modules/caddyhttp/server.go
index ca83c5a..e8bf900 100644
--- a/modules/caddyhttp/server.go
+++ b/modules/caddyhttp/server.go
@@ -170,8 +170,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
repl.Set("http.response.latency", latency)
logger := accLog
- if loggerName := s.Logs.getLoggerName(r.Host); loggerName != "" {
- logger = logger.Named(loggerName)
+ if s.Logs != nil {
+ logger = s.Logs.wrapLogger(logger, r.Host)
}
log := logger.Info
@@ -200,8 +200,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err != nil {
// prepare the error log
logger := errLog
- if loggerName := s.Logs.getLoggerName(r.Host); loggerName != "" {
- logger = logger.Named(loggerName)
+ if s.Logs != nil {
+ logger = s.Logs.wrapLogger(logger, r.Host)
}
// get the values that will be used to log the error
@@ -378,6 +378,14 @@ type ServerLogConfig struct {
LoggerNames map[string]string `json:"logger_names,omitempty"`
}
+// wrapLogger wraps logger in a logger named according to user preferences for the given host.
+func (slc ServerLogConfig) wrapLogger(logger *zap.Logger, host string) *zap.Logger {
+ if loggerName := slc.getLoggerName(host); loggerName != "" {
+ return logger.Named(loggerName)
+ }
+ return logger
+}
+
func (slc ServerLogConfig) getLoggerName(host string) string {
if loggerName, ok := slc.LoggerNames[host]; ok {
return loggerName