Skip to content

Conversation

@elboulangero
Copy link
Contributor

The 1st commit is a minor adjustment of what was just merged in #191, after thinking about it a bit harder (sorry that I didn't get that right at first try).

The other commits rework the code to make it more readable, it's pretty trivial, I couldn't help.

Bonus: 1 new unit test!

In recent commit 2285d2a, we added the method to the download logs.
We've put it after the request path, as such: `method:<METHOD>`. So it
looked like that:

    2025/04/01 06:51:07.686160 REDIRECT 302 "/README" method:HEAD ip:1.2.3.4 mirror:mirror.foobar asn:1234 distance:42km countries:AB

After thinking a bit more, I'd like to adjust. Here's why.

The format `field:value` is useful when a field can be nil (`ip` can be
nil in case of error), or to distinguish between optional and mandatory
fields (for example: `mirror`, `asn`, `distance`, and `countries` are
optional, they are not present in case of 404).

However, we now log the method in all cases, and it's never nil, so
there's no good reason to log it with the `field:value` format.

So instead, let's log it as is, just before the request path.

After this commit, the line of log above looks like that:

    2025/04/01 06:51:07.686160 REDIRECT 302 HEAD "/README" ip:xxx.xxx.xxx.xxx mirror:mirror.foo.bar asn:1234 distance:42km countries:AB
With this trivial change, it's getting a bit clearer that the lines of
logs have the same beginning in all cases.
It's now crystal clear that the lines of logs have the same beginning in
all cases. We're going to factorize that in the next commit.
Create the line of logs in two passes: the first part of the line is
the same in all cases, it's only the second part that varies depending
on the situation. Now it's clear from reading the code.
@jbkempf jbkempf merged commit 39b833c into etix:master Apr 2, 2025
3 checks passed
@elboulangero elboulangero deleted the downloads-logs-again branch April 2, 2025 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants