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

Add access logging functionality #713

Merged
merged 1 commit into from
May 22, 2021
Merged

Add access logging functionality #713

merged 1 commit into from
May 22, 2021

Conversation

fredrikekre
Copy link
Member

@fredrikekre fredrikekre commented May 17, 2021

This adds access logging functionality to HTTP.listen/HTTP.serve. This includes a string macro that parses NGINX style format strings (chose that since it is pretty readable, self-explanatory, and looks more like Julia code compared to e.g. Apache format strings).

Example usage:

HTTP.listen(handler, host, port; access_log = logfmt"$remote_addr $request")

which would then log

[ Info: ::1 GET / HTTP/1.1
[ Info: ::1 POST /hello/post HTTP/1.1
[ Info: ::ffff:7f00:1 POST /hello/post HTTP/1.1
[ Info: ::ffff:7f00:1 HEAD /hello/post HTTP/1.1

etc.

Originally I thought this had to be implemented "on the inside" in order to get access to e.g. number of written bytes etc, but (as done in this PR) those things can technically be stored in the http::Stream object and you could do:

HTTP.listen(host, port) do http
    # handle stuff
    do_log(http) # do logging like this instead
end

but it is pretty convenient to just have to pass the access_log keyword and it does not really cost anything. In addition, if you want manual control you can still do it like above.

@fredrikekre fredrikekre force-pushed the fe/access_log branch 2 times, most recently from 87a8dd7 to b7d6d1c Compare May 20, 2021 00:15
@fredrikekre fredrikekre marked this pull request as ready for review May 20, 2021 00:15
@fredrikekre fredrikekre changed the title [WIP/RFC]: Add access logging functionality Add access logging functionality May 20, 2021
@codecov-commenter
Copy link

codecov-commenter commented May 20, 2021

Codecov Report

Merging #713 (ed8afb1) into master (d4a7bbe) will increase coverage by 0.48%.
The diff coverage is 94.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #713      +/-   ##
==========================================
+ Coverage   76.04%   76.52%   +0.48%     
==========================================
  Files          36       37       +1     
  Lines        2371     2437      +66     
==========================================
+ Hits         1803     1865      +62     
- Misses        568      572       +4     
Impacted Files Coverage Δ
src/HTTP.jl 97.82% <ø> (ø)
src/access_log.jl 93.22% <93.22%> (ø)
src/Servers.jl 81.25% <100.00%> (+0.35%) ⬆️
src/Streams.jl 96.20% <100.00%> (+0.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d4a7bbe...ed8afb1. Read the comment docs.

Copy link
Member

@oxinabox oxinabox left a comment

Choose a reason for hiding this comment

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

Basically LGTM.
Other than a few things, most importantly making sure it doesn't break existing code if it doesn't have to.

src/Servers.jl Outdated Show resolved Hide resolved
src/Streams.jl Outdated Show resolved Hide resolved
src/access_log.jl Show resolved Hide resolved
test/server.jl Outdated Show resolved Hide resolved
@fredrikekre fredrikekre force-pushed the fe/access_log branch 2 times, most recently from 7f08722 to 980d5c1 Compare May 22, 2021 22:48
@fredrikekre
Copy link
Member Author

Thanks for the review, updated all of it I think (and fixed tests on Windows).

@oxinabox
Copy link
Member

oxinabox commented May 22, 2021

You have merge rights here, yes?
Merge when you are happy

@fredrikekre fredrikekre merged commit 1ed5fde into master May 22, 2021
@fredrikekre fredrikekre deleted the fe/access_log branch May 22, 2021 23:34
@quinnj
Copy link
Member

quinnj commented May 25, 2021

Yeah, sorry for the slow review; this looks great!

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.

4 participants