From 2a127ac3d1650052f39e93f277e1dfd8c7c730e4 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Fri, 12 Mar 2021 15:00:02 -0500 Subject: caddyconfig: add global option for configuring loggers (#4028) This change is aimed at enhancing the logging module within the Caddyfile directive to allow users to configure logs other than the HTTP access log stream, which is the current capability of the Caddyfile [1]. The intent here is to leverage the same syntax as the server log directive at a global level, so that similar customizations can be added without needing to resort to a JSON-based configuration. Discussion for this approach happened in the referenced issue. Closes https://github.com/caddyserver/caddy/issues/3958 [1] https://caddyserver.com/docs/caddyfile/directives/log --- .../global_options_log_and_site.txt | 77 ++++++++++++++++++++++ .../caddyfile_adapt/global_options_log_basic.txt | 18 +++++ .../caddyfile_adapt/global_options_log_custom.txt | 39 +++++++++++ .../caddyfile_adapt/global_options_log_multi.txt | 26 ++++++++ 4 files changed, 160 insertions(+) create mode 100644 caddytest/integration/caddyfile_adapt/global_options_log_and_site.txt create mode 100644 caddytest/integration/caddyfile_adapt/global_options_log_basic.txt create mode 100644 caddytest/integration/caddyfile_adapt/global_options_log_custom.txt create mode 100644 caddytest/integration/caddyfile_adapt/global_options_log_multi.txt (limited to 'caddytest/integration') diff --git a/caddytest/integration/caddyfile_adapt/global_options_log_and_site.txt b/caddytest/integration/caddyfile_adapt/global_options_log_and_site.txt new file mode 100644 index 0000000..037c8b6 --- /dev/null +++ b/caddytest/integration/caddyfile_adapt/global_options_log_and_site.txt @@ -0,0 +1,77 @@ +{ + log { + output file caddy.log + include some-log-source + exclude admin.api admin2.api + } + log custom-logger { + output file caddy.log + level WARN + include custom-log-source + } +} + +:8884 { + log { + format json + output file access.log + } +} +---------- +{ + "logging": { + "logs": { + "custom-logger": { + "writer": { + "filename": "caddy.log", + "output": "file" + }, + "level": "WARN", + "include": [ + "custom-log-source" + ] + }, + "default": { + "writer": { + "filename": "caddy.log", + "output": "file" + }, + "include": [ + "some-log-source" + ], + "exclude": [ + "admin.api", + "admin2.api", + "custom-log-source", + "http.log.access.log0" + ] + }, + "log0": { + "writer": { + "filename": "access.log", + "output": "file" + }, + "encoder": { + "format": "json" + }, + "include": [ + "http.log.access.log0" + ] + } + } + }, + "apps": { + "http": { + "servers": { + "srv0": { + "listen": [ + ":8884" + ], + "logs": { + "default_logger_name": "log0" + } + } + } + } + } +} diff --git a/caddytest/integration/caddyfile_adapt/global_options_log_basic.txt b/caddytest/integration/caddyfile_adapt/global_options_log_basic.txt new file mode 100644 index 0000000..b8d32dc --- /dev/null +++ b/caddytest/integration/caddyfile_adapt/global_options_log_basic.txt @@ -0,0 +1,18 @@ +{ + log { + output file foo.log + } +} +---------- +{ + "logging": { + "logs": { + "default": { + "writer": { + "filename": "foo.log", + "output": "file" + } + } + } + } +} diff --git a/caddytest/integration/caddyfile_adapt/global_options_log_custom.txt b/caddytest/integration/caddyfile_adapt/global_options_log_custom.txt new file mode 100644 index 0000000..abbca19 --- /dev/null +++ b/caddytest/integration/caddyfile_adapt/global_options_log_custom.txt @@ -0,0 +1,39 @@ +{ + log custom-logger { + format filter { + wrap console + fields { + common_log delete + request>remote_addr ip_mask { + ipv4 24 + ipv6 32 + } + } + } + } +} +---------- +{ + "logging": { + "logs": { + "custom-logger": { + "encoder": { + "fields": { + "common_log": { + "filter": "delete" + }, + "request\u003eremote_addr": { + "filter": "ip_mask", + "ipv4_cidr": 24, + "ipv6_cidr": 32 + } + }, + "format": "filter", + "wrap": { + "format": "console" + } + } + } + } + } +} diff --git a/caddytest/integration/caddyfile_adapt/global_options_log_multi.txt b/caddytest/integration/caddyfile_adapt/global_options_log_multi.txt new file mode 100644 index 0000000..c20251a --- /dev/null +++ b/caddytest/integration/caddyfile_adapt/global_options_log_multi.txt @@ -0,0 +1,26 @@ +{ + log first { + output file foo.log + } + log second { + format json + } +} +---------- +{ + "logging": { + "logs": { + "first": { + "writer": { + "filename": "foo.log", + "output": "file" + } + }, + "second": { + "encoder": { + "format": "json" + } + } + } + } +} -- cgit v1.2.3