mirror of https://github.com/caddyserver/caddy.git
parent
9991fdc495
commit
999ab22b8c
|
@ -85,7 +85,7 @@ func cmdFileServer(fs caddycmd.Flags) (int, error) {
|
||||||
|
|
||||||
if domain != "" {
|
if domain != "" {
|
||||||
route.MatcherSetsRaw = []caddy.ModuleMap{
|
route.MatcherSetsRaw = []caddy.ModuleMap{
|
||||||
caddy.ModuleMap{
|
{
|
||||||
"host": caddyconfig.JSON(caddyhttp.MatchHost{domain}, nil),
|
"host": caddyconfig.JSON(caddyhttp.MatchHost{domain}, nil),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,8 +170,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
repl.Set("http.response.latency", latency)
|
repl.Set("http.response.latency", latency)
|
||||||
|
|
||||||
logger := accLog
|
logger := accLog
|
||||||
if loggerName := s.Logs.getLoggerName(r.Host); loggerName != "" {
|
if s.Logs != nil {
|
||||||
logger = logger.Named(loggerName)
|
logger = s.Logs.wrapLogger(logger, r.Host)
|
||||||
}
|
}
|
||||||
|
|
||||||
log := logger.Info
|
log := logger.Info
|
||||||
|
@ -200,8 +200,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// prepare the error log
|
// prepare the error log
|
||||||
logger := errLog
|
logger := errLog
|
||||||
if loggerName := s.Logs.getLoggerName(r.Host); loggerName != "" {
|
if s.Logs != nil {
|
||||||
logger = logger.Named(loggerName)
|
logger = s.Logs.wrapLogger(logger, r.Host)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the values that will be used to log the error
|
// 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"`
|
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 {
|
func (slc ServerLogConfig) getLoggerName(host string) string {
|
||||||
if loggerName, ok := slc.LoggerNames[host]; ok {
|
if loggerName, ok := slc.LoggerNames[host]; ok {
|
||||||
return loggerName
|
return loggerName
|
||||||
|
|
Loading…
Reference in New Issue