summaryrefslogtreecommitdiff
path: root/caddytest
diff options
context:
space:
mode:
authorAaron Taylor <git@ataylor.io>2021-03-12 15:00:02 -0500
committerGitHub <noreply@github.com>2021-03-12 13:00:02 -0700
commit2a127ac3d1650052f39e93f277e1dfd8c7c730e4 (patch)
tree912bb9a181d0a4139b5b3320ff1bb8c938da5c04 /caddytest
parent802f80c3821940825ec278e1d9c153a321e956a9 (diff)
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
Diffstat (limited to 'caddytest')
-rw-r--r--caddytest/integration/caddyfile_adapt/global_options_log_and_site.txt77
-rw-r--r--caddytest/integration/caddyfile_adapt/global_options_log_basic.txt18
-rw-r--r--caddytest/integration/caddyfile_adapt/global_options_log_custom.txt39
-rw-r--r--caddytest/integration/caddyfile_adapt/global_options_log_multi.txt26
4 files changed, 160 insertions, 0 deletions
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"
+ }
+ }
+ }
+ }
+}