diff options
author | Francis Lavoie <[email protected]> | 2024-04-16 18:26:18 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2024-04-16 22:26:18 +0000 |
commit | 70953e873a559553e97c985a13db897ab9f573ff (patch) | |
tree | cade4037d41f21a0fb16ca879f098d6d010ea010 /caddytest | |
parent | eafc875ea9f6238fce24b23af47a1d7162fd27a5 (diff) | |
download | caddy-70953e873a559553e97c985a13db897ab9f573ff.tar.gz caddy-70953e873a559553e97c985a13db897ab9f573ff.zip |
caddyhttp: Support multiple logger names per host (#6088)
* caddyhttp: Support multiple logger names per host
* Lint
* Add adapt test
* Implement "string or array" parsing, keep original `logger_names`
* Rewrite adapter test to be more representative of the usecase
Diffstat (limited to 'caddytest')
7 files changed, 147 insertions, 10 deletions
diff --git a/caddytest/integration/caddyfile_adapt/import_args_snippet.caddyfiletest b/caddytest/integration/caddyfile_adapt/import_args_snippet.caddyfiletest index 10d9f4cfc..9d5c25352 100644 --- a/caddytest/integration/caddyfile_adapt/import_args_snippet.caddyfiletest +++ b/caddytest/integration/caddyfile_adapt/import_args_snippet.caddyfiletest @@ -72,8 +72,12 @@ b.example.com { ], "logs": { "logger_names": { - "a.example.com": "log0", - "b.example.com": "log1" + "a.example.com": [ + "log0" + ], + "b.example.com": [ + "log1" + ] } } } diff --git a/caddytest/integration/caddyfile_adapt/log_except_catchall_blocks.caddyfiletest b/caddytest/integration/caddyfile_adapt/log_except_catchall_blocks.caddyfiletest index e1362f8fb..b2a7f2afc 100644 --- a/caddytest/integration/caddyfile_adapt/log_except_catchall_blocks.caddyfiletest +++ b/caddytest/integration/caddyfile_adapt/log_except_catchall_blocks.caddyfiletest @@ -99,7 +99,9 @@ http://localhost:2020 { }, "logs": { "logger_names": { - "localhost": "" + "localhost": [ + "" + ] }, "skip_unmapped_hosts": true } diff --git a/caddytest/integration/caddyfile_adapt/log_multi_logger_name.caddyfiletest b/caddytest/integration/caddyfile_adapt/log_multi_logger_name.caddyfiletest new file mode 100644 index 000000000..be9ec1885 --- /dev/null +++ b/caddytest/integration/caddyfile_adapt/log_multi_logger_name.caddyfiletest @@ -0,0 +1,117 @@ +(log-both) { + log {args[0]}-json { + hostnames {args[0]} + output file /var/log/{args[0]}.log + format json + } + log {args[0]}-console { + hostnames {args[0]} + output file /var/log/{args[0]}.json + format console + } +} + +*.example.com { + # Subdomains log to multiple files at once, with + # different output files and formats. + import log-both foo.example.com + import log-both bar.example.com +} +---------- +{ + "logging": { + "logs": { + "bar.example.com-console": { + "writer": { + "filename": "/var/log/bar.example.com.json", + "output": "file" + }, + "encoder": { + "format": "console" + }, + "include": [ + "http.log.access.bar.example.com-console" + ] + }, + "bar.example.com-json": { + "writer": { + "filename": "/var/log/bar.example.com.log", + "output": "file" + }, + "encoder": { + "format": "json" + }, + "include": [ + "http.log.access.bar.example.com-json" + ] + }, + "default": { + "exclude": [ + "http.log.access.bar.example.com-console", + "http.log.access.bar.example.com-json", + "http.log.access.foo.example.com-console", + "http.log.access.foo.example.com-json" + ] + }, + "foo.example.com-console": { + "writer": { + "filename": "/var/log/foo.example.com.json", + "output": "file" + }, + "encoder": { + "format": "console" + }, + "include": [ + "http.log.access.foo.example.com-console" + ] + }, + "foo.example.com-json": { + "writer": { + "filename": "/var/log/foo.example.com.log", + "output": "file" + }, + "encoder": { + "format": "json" + }, + "include": [ + "http.log.access.foo.example.com-json" + ] + } + } + }, + "apps": { + "http": { + "servers": { + "srv0": { + "listen": [ + ":443" + ], + "routes": [ + { + "match": [ + { + "host": [ + "*.example.com" + ] + } + ], + "terminal": true + } + ], + "logs": { + "logger_names": { + "bar.example.com": [ + "bar.example.com-json", + "bar.example.com-console" + ], + "foo.example.com": [ + "foo.example.com-json", + "foo.example.com-console" + ] + } + } + } + } + } + } +}
\ No newline at end of file diff --git a/caddytest/integration/caddyfile_adapt/log_override_hostname.caddyfiletest b/caddytest/integration/caddyfile_adapt/log_override_hostname.caddyfiletest index c36ba23f8..b9213e65a 100644 --- a/caddytest/integration/caddyfile_adapt/log_override_hostname.caddyfiletest +++ b/caddytest/integration/caddyfile_adapt/log_override_hostname.caddyfiletest @@ -75,9 +75,15 @@ example.com:8443 { ], "logs": { "logger_names": { - "bar.example.com": "log0", - "baz.example.com": "log1", - "foo.example.com": "log0" + "bar.example.com": [ + "log0" + ], + "baz.example.com": [ + "log1" + ], + "foo.example.com": [ + "log0" + ] } } }, @@ -99,7 +105,9 @@ example.com:8443 { ], "logs": { "logger_names": { - "example.com": "log2" + "example.com": [ + "log2" + ] } } } diff --git a/caddytest/integration/caddyfile_adapt/log_override_name_multiaccess.caddyfiletest b/caddytest/integration/caddyfile_adapt/log_override_name_multiaccess.caddyfiletest index d48857a2d..2708503e5 100644 --- a/caddytest/integration/caddyfile_adapt/log_override_name_multiaccess.caddyfiletest +++ b/caddytest/integration/caddyfile_adapt/log_override_name_multiaccess.caddyfiletest @@ -76,7 +76,9 @@ http://localhost:8881 { }, "logs": { "logger_names": { - "localhost": "foo" + "localhost": [ + "foo" + ] } } } diff --git a/caddytest/integration/caddyfile_adapt/log_override_name_multiaccess_debug.caddyfiletest b/caddytest/integration/caddyfile_adapt/log_override_name_multiaccess_debug.caddyfiletest index d024dc386..7ea659789 100644 --- a/caddytest/integration/caddyfile_adapt/log_override_name_multiaccess_debug.caddyfiletest +++ b/caddytest/integration/caddyfile_adapt/log_override_name_multiaccess_debug.caddyfiletest @@ -81,7 +81,9 @@ http://localhost:8881 { }, "logs": { "logger_names": { - "localhost": "foo" + "localhost": [ + "foo" + ] } } } diff --git a/caddytest/integration/caddyfile_adapt/log_skip_hosts.caddyfiletest b/caddytest/integration/caddyfile_adapt/log_skip_hosts.caddyfiletest index 8fdd57156..c10610c2e 100644 --- a/caddytest/integration/caddyfile_adapt/log_skip_hosts.caddyfiletest +++ b/caddytest/integration/caddyfile_adapt/log_skip_hosts.caddyfiletest @@ -63,7 +63,9 @@ example.com { ], "logs": { "logger_names": { - "one.example.com": "" + "one.example.com": [ + "" + ] }, "skip_hosts": [ "example.com", |