Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

caddyhttp: Support multiple logger names per host #6088

Merged
merged 5 commits into from
Apr 16, 2024
Merged

Conversation

francislavoie
Copy link
Member

@francislavoie francislavoie commented Feb 9, 2024

Context: https://caddy.community/t/config-cleanup-for-logging-blocking-and-a-signalr-issue/22643

I realized that there's currently no good way to point a specific hostname to write to more than one logger at once, because logger_names is a simple map[string]string (so only one value per key).

To solve this, I'm deprecating logger_names and adding a new logger_mapping (which Caddyfile immediately uses) I'm changing logger_names to be a map[string]StringArray which is a type which accepts either a JSON string or array (where a string gets turned into a one-element string slice). Then, I reworked the logging code in the server to loop over the list of wrapped loggers.

I'm not 100% convinced about the logger_mapping name... I'd rather reuse logger_names, but obviously we can't do that, it would be a breaking change. Any better naming ideas? Resolved by doing custom JSON unmarshaling.

@francislavoie francislavoie added the feature ⚙️ New feature or request label Feb 9, 2024
@francislavoie francislavoie added this to the v2.8.0 milestone Feb 9, 2024
@mohammed90
Copy link
Member

I'd rather reuse logger_names, but obviously we can't do that, it would be a breaking change. Any better naming ideas?

We can do custom unmarshaling by implementing the JSONUnmarshal (or is it better to use TextUnmarshal? 🤔) method. In it we'll check if it can be marshalled into a map[string][]string or map[string]string, reporting a warning when marshalling into a map[string]string.

@francislavoie
Copy link
Member Author

I guess so. 🤔 Most of the time that approach feels wrong but in this case it can be transparent so it's probably fine.

@francislavoie
Copy link
Member Author

Thanks for the idea @mohammed90! Much better I think.

@francislavoie
Copy link
Member Author

The user tried it out and confirmed it resolves their usecase:

https://caddy.community/t/config-cleanup-for-logging-blocking-and-a-signalr-issue/22643/12

@mohammed90
Copy link
Member

Thanks for the idea @mohammed90! Much better I think.

Great 😃 I have to update the nginx-adapter after this PR

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks quite complicated to me 🙈 but if it works and is useful for real world use cases, I guess that's how it goes (my fault for the logging design). Thank you for the tricky patch!!

@francislavoie francislavoie enabled auto-merge (squash) April 16, 2024 22:21
@francislavoie francislavoie merged commit 70953e8 into master Apr 16, 2024
25 checks passed
@francislavoie francislavoie deleted the multi-loggers branch April 16, 2024 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ⚙️ New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants