Log { except <path> } directive in v2?

1. Caddy version (caddy version):

v2.2.0-rc.1-8-g744d04c2

2. How I run Caddy:

caddy run --config ./Caddyfile.json

a. System environment:

Raspbian 8.0 (Jessie)
shellinabox running on port 8080

b. Command:

see above

c. Service/unit/compose file:

not applicable here

d. My complete Caddyfile or JSON config:

{
	"logging": {
		"logs": {
			"default": {
				"exclude": [
					"http.log.access.log0"
				]
			},
			"log0": {
				"writer": {
					"filename": "./www/access.txt",
					"output": "file"
				},
				"encoder": {
					"field": "common_log",
					"format": "single_field"
				},
				"include": [
					"http.log.access.log0"
				]
			}
		}
	},
	"apps": {
		"http": {
			"servers": {
				"srv0": {
					"listen": [
						":443"
					],
					"routes": [
						{
							"match": [
								{
									"host": [
										"192.168.43.223"
									]
								}
							],
							"handle": [
								{
									"handler": "subroute",
									"routes": [
										{
											"handle": [
												{
													"handler": "vars",
													"root": "/home/pi/www"
												},
												{
													"encodings": {
														"gzip": {},
														"zstd": {}
													},
													"handler": "encode"
												}
											]
										},
										{
											"handle": [
												{
													"handler": "reverse_proxy",
													"upstreams": [
														{
															"dial": "localhost:8080"
														}
													]
												}
											],
											"match": [
												{
													"path": [
														"/shell/*"
													]
												}
											]
										}
									]
								}
							],
							"terminal": true
						}
					],
					"logs": {
						"logger_names": {
							"192.168.43.223": "log0"
						},
						"skip_hosts": ["192.168.43.223/shell/"]
					}
				}
			}
		},
		"tls": {
			"automation": {
				"policies": [
					{
						"subjects": [
							"192.168.43.223"
						],
						"issuer": {
							"module": "internal"
						}
					}
				]
			}
		}
	}
}

3. The problem I’m having:

Caddy and shellinabox work just fine but I’d prefer not to have a log entry upon every keypress in the [shellinabox] shell. I had been able to avoid that with the “except <path>” Caddyfile directive in v1:

log / access.txt {
 except /shell
}

4. Error messages and/or full log output:

192.168.43.195 - - [30/Aug/2020:18:11:34 +0200] “POST /shell/? HTTP/2.0” 200 46
192.168.43.195 - - [30/Aug/2020:18:11:34 +0200] “POST /shell/? HTTP/2.0” 200 56
192.168.43.195 - - [30/Aug/2020:18:11:46 +0200] “POST /shell/? HTTP/2.0” 200 327
192.168.43.195 - - [30/Aug/2020:18:11:47 +0200] “POST /shell/? HTTP/2.0” 200 327
192.168.43.195 - - [30/Aug/2020:18:11:47 +0200] “POST /shell/? HTTP/2.0” 200 47
192.168.43.195 - - [30/Aug/2020:18:11:47 +0200] “POST /shell/? HTTP/2.0” 200 327
192.168.43.195 - - [30/Aug/2020:18:11:47 +0200] “POST /shell/? HTTP/2.0” 200 47

5. What I already tried:

above “skip_hosts” statement in different variants in the JSON config.
(it does work for the “plain” host - but I am looking for a way to filter access to the /shell path only… )

6. Links to relevant resources:

Fudging, but works for me:
In modules/logging/encoders.go, appended

			if (strings.Contains(buf.String(), "/shell/?")) {
				buf.Reset()	
			}

in EncodeEntry before return.

Can close this

You could write a log writer plugin which can be configured to ignore certain kinds of logs

This topic was automatically closed after 30 days. New replies are no longer allowed.