Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 11, 12:15 UTC
httpcaddyfile: accept duration strings for log sampling interval (#7694)
Co-authored-by: tomholford <tomholford@users.noreply.github.com>
tomholford committed
May 7, 2026 at 11:32 UTC
0780d4489cc7199b87598b15aad3270e851ac138
4 files changed
+7
-7
caddyconfig/httpcaddyfile/builtins.go
+1
-1
@@ -1053,7 +1053,7 @@ func parseLogHelper(h Helper, globalLogNames map[string]struct{}) ([]ConfigValue
1053
if !d.NextArg() {
1054
return nil, d.ArgErr()
1055
}
1056
- interval, err := time.ParseDuration(d.Val() + "ns")
1056
+ interval, err := caddy.ParseDuration(d.Val())
1057
if err != nil {
1058
return nil, d.Errf("failed to parse interval: %v", err)
1059
}
caddyconfig/httpcaddyfile/builtins_test.go
+2
-2
@@ -66,14 +66,14 @@ func TestLogDirectiveSyntax(t *testing.T) {
66
input: `:8080 {
67
log {
68
sampling {
69
- interval 2
69
+ interval 2s
70
first 3
71
thereafter 4
72
}
73
}
74
}
75
`,
76
- output: `{"logging":{"logs":{"default":{"exclude":["http.log.access.log0"]},"log0":{"sampling":{"interval":2,"first":3,"thereafter":4},"include":["http.log.access.log0"]}}},"apps":{"http":{"servers":{"srv0":{"listen":[":8080"],"logs":{"default_logger_name":"log0"}}}}}}`,
76
+ output: `{"logging":{"logs":{"default":{"exclude":["http.log.access.log0"]},"log0":{"sampling":{"interval":2000000000,"first":3,"thereafter":4},"include":["http.log.access.log0"]}}},"apps":{"http":{"servers":{"srv0":{"listen":[":8080"],"logs":{"default_logger_name":"log0"}}}}}}`,
77
expectError: false,
78
},
79
} {
caddytest/integration/caddyfile_adapt/global_options_log_sampling.caddyfiletest
+2
-2
@@ -1,7 +1,7 @@
1
{
2
log {
3
sampling {
4
- interval 300
4
+ interval 5m
5
first 50
6
thereafter 40
7
}
@@ -13,7 +13,7 @@
13
"logs": {
14
"default": {
15
"sampling": {
16
- "interval": 300,
16
+ "interval": 300000000000,
17
"first": 50,
18
"thereafter": 40
19
}
caddytest/integration/caddyfile_adapt/log_sampling.caddyfiletest
+2
-2
@@ -1,7 +1,7 @@
1
:80 {
2
log {
3
sampling {
4
- interval 300
4
+ interval 5m
5
first 50
6
thereafter 40
7
}
@@ -18,7 +18,7 @@
18
},
19
"log0": {
20
"sampling": {
21
- "interval": 300,
21
+ "interval": 300000000000,
22
"first": 50,
23
"thereafter": 40
24
},