caddy icon indicating copy to clipboard operation
caddy copied to clipboard

logging: Add support for additional logger filters other than hostname

Open armadi1809 opened this issue 1 year ago • 7 comments

closes #5978

@francislavoie This took some time but here is my initial implementation of this. Would like to get your feedback on this and your thoughts on what other tests should go in here? Thanks.

armadi1809 avatar Feb 04 '24 23:02 armadi1809

Like I said in the issue, I'm not totally convinced this is the right way to do this. But I can't really think of anything better.

I think no_hostname is better than no_host_name, because hostname is typically seen as a single word in the context web servers (see https://en.wikipedia.org/wiki/Hostname for example)

I think there should be a d.NextArg() when parsing that option to reject the config if an extra argument is passed, since it takes none right now.

I'm not sure if that's the best name though, I'd like @mholt's opinion.

francislavoie avatar Feb 05 '24 08:02 francislavoie

@francislavoie, all the feedback items above should be resolved, except for the potential merge conflict with multiple hostnames.

armadi1809 avatar Feb 13 '24 16:02 armadi1809

@francislavoie @armadi1809 Let me know if you want to discuss anything to wrap up this PR. :+1:

mholt avatar Apr 15 '24 17:04 mholt

If I remember correctly this needs to wait for #6088 to be merged as it will require some changes after that's done right? @francislavoie

armadi1809 avatar Apr 16 '24 22:04 armadi1809

I'm merging it now (once CI passes) 👍 you can rebase your branch and make the necessary adjustments.

francislavoie avatar Apr 16 '24 22:04 francislavoie

Needs another rebase, there's a conflict with another recent change of mine. Sorry!

francislavoie avatar Apr 24 '24 21:04 francislavoie

@francislavoie, rebase done. Any thoughts on the open discussion above?

armadi1809 avatar Apr 26 '24 00:04 armadi1809

I did a commit to do a final bit of cleanup and refactoring. I think this is good to go now.

francislavoie avatar May 11 '24 13:05 francislavoie

Awesome, thank you both!!

mholt avatar May 11 '24 13:05 mholt

Just wanted to say THANK YOU for this awesome new feature. I have just tested it with Caddy v2.8.0-rc and my configuration looked like this (maybe this helps for other users, viewers of this MR or for the caddy docs website).

example.com {
        log example.com

        log health_check_log {
                output file /var/log/caddy/access-health-checks.json {
                        roll_size 50m
                        roll_local_time
                        roll_keep_for 30d
                }
                format filter {
                        wrap json
                        fields {
                                request>tls>version tls_version TLSv
                                request>tls>cipher_suite tls_cipher
                        }
                }
                no_hostname
        }

	@monitoring_ohdear_uptime {
		# Two possible user-agent headers:
		# Mozilla/5.0 (compatible; OhDear/1.1; +https://ohdear.app/checker; brokenLinks)
		# OhDear.app (+https://ohdear.app/docs/checks/uptime)
		header_regexp user-agent `^.*\+https:\/\/ohdear\.app.*$`
		header_regexp X-External-Monitoring ^redacted_secret$
	}

        # Before Caddy v.2.8.0 these requests were skipped; now commented
        #log_skip @monitoring_ohdear_uptime

        # Now with Caddy v2.8.0-rc.1 these requests are written into a dedicated file 👍 
        log_name @monitoring_ohdear_uptime health_check_log
 ...

steffenbusch avatar May 24 '24 10:05 steffenbusch