aboutsummaryrefslogtreecommitdiffhomepage
path: root/caddyconfig
diff options
context:
space:
mode:
Diffstat (limited to 'caddyconfig')
-rw-r--r--caddyconfig/httpcaddyfile/builtins.go21
-rw-r--r--caddyconfig/httpcaddyfile/directives.go1
-rw-r--r--caddyconfig/httpcaddyfile/httptype.go16
3 files changed, 33 insertions, 5 deletions
diff --git a/caddyconfig/httpcaddyfile/builtins.go b/caddyconfig/httpcaddyfile/builtins.go
index 27ab0a182..35a08ef27 100644
--- a/caddyconfig/httpcaddyfile/builtins.go
+++ b/caddyconfig/httpcaddyfile/builtins.go
@@ -51,6 +51,7 @@ func init() {
RegisterDirective("log", parseLog)
RegisterHandlerDirective("skip_log", parseLogSkip)
RegisterHandlerDirective("log_skip", parseLogSkip)
+ RegisterHandlerDirective("log_name", parseLogName)
}
// parseBind parses the bind directive. Syntax:
@@ -914,7 +915,7 @@ func parseLogHelper(h Helper, globalLogNames map[string]struct{}) ([]ConfigValue
// this is useful for setting up loggers per subdomain in a site block
// with a wildcard domain
customHostnames := []string{}
-
+ noHostname := false
for h.NextBlock(0) {
switch h.Val() {
case "hostnames":
@@ -1000,6 +1001,12 @@ func parseLogHelper(h Helper, globalLogNames map[string]struct{}) ([]ConfigValue
cl.Exclude = append(cl.Exclude, h.Val())
}
+ case "no_hostname":
+ if h.NextArg() {
+ return nil, h.ArgErr()
+ }
+ noHostname = true
+
default:
return nil, h.Errf("unrecognized subdirective: %s", h.Val())
}
@@ -1007,7 +1014,7 @@ func parseLogHelper(h Helper, globalLogNames map[string]struct{}) ([]ConfigValue
var val namedCustomLog
val.hostnames = customHostnames
-
+ val.noHostname = noHostname
isEmptyConfig := reflect.DeepEqual(cl, new(caddy.CustomLog))
// Skip handling of empty logging configs
@@ -1058,3 +1065,13 @@ func parseLogSkip(h Helper) (caddyhttp.MiddlewareHandler, error) {
}
return caddyhttp.VarsMiddleware{"log_skip": true}, nil
}
+
+// parseLogName parses the log_name directive. Syntax:
+//
+// log_name <names...>
+func parseLogName(h Helper) (caddyhttp.MiddlewareHandler, error) {
+ h.Next() // consume directive name
+ return caddyhttp.VarsMiddleware{
+ caddyhttp.AccessLoggerNameVarKey: h.RemainingArgs(),
+ }, nil
+}
diff --git a/caddyconfig/httpcaddyfile/directives.go b/caddyconfig/httpcaddyfile/directives.go
index 172594218..3e688ebcf 100644
--- a/caddyconfig/httpcaddyfile/directives.go
+++ b/caddyconfig/httpcaddyfile/directives.go
@@ -53,6 +53,7 @@ var defaultDirectiveOrder = []string{
"log_append",
"skip_log", // TODO: deprecated, renamed to log_skip
"log_skip",
+ "log_name",
"header",
"copy_response_headers", // only in reverse_proxy's handle_response
diff --git a/caddyconfig/httpcaddyfile/httptype.go b/caddyconfig/httpcaddyfile/httptype.go
index 8e7d21fa0..a8a2ae5b3 100644
--- a/caddyconfig/httpcaddyfile/httptype.go
+++ b/caddyconfig/httpcaddyfile/httptype.go
@@ -797,6 +797,15 @@ func (st *ServerType) serversFromPairings(
sblockLogHosts := sblock.hostsFromKeys(true)
for _, cval := range sblock.pile["custom_log"] {
ncl := cval.Value.(namedCustomLog)
+
+ // if `no_hostname` is set, then this logger will not
+ // be associated with any of the site block's hostnames,
+ // and only be usable via the `log_name` directive
+ // or the `access_logger_names` variable
+ if ncl.noHostname {
+ continue
+ }
+
if sblock.hasHostCatchAllKey() && len(ncl.hostnames) == 0 {
// all requests for hosts not able to be listed should use
// this log because it's a catch-all-hosts server block
@@ -1598,9 +1607,10 @@ func (c counter) nextGroup() string {
}
type namedCustomLog struct {
- name string
- hostnames []string
- log *caddy.CustomLog
+ name string
+ hostnames []string
+ log *caddy.CustomLog
+ noHostname bool
}
// sbAddrAssociation is a mapping from a list of