-
Notifications
You must be signed in to change notification settings - Fork 0
Log format improvements #6
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
Conversation
76e1ea8 to
ddd075d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some commentary ... 💬
config/log.conf
Outdated
| '}'; | ||
|
|
||
| access_log /dev/stdout main_default; | ||
| access_log /dev/stdout main_json; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dunno if changing the default logging is agreeable but figured in 2021 we might as well move to structured logging and so having this in JSON is a good default! 😅 Makes parsing it easier!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I should have mentioned that the reason I left main_default in was because it allows one to override access_log /dev/stdout main_default; elsewhere e.g. like in a location block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dunno if changing the default logging is agreeable but figured in 2021 we might as well move to structured logging and so having this in JSON is a good default! 😅 Makes parsing it easier!!
It's bittersweet after seeing human-readable lines for so long. 😭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's bittersweet after seeing human-readable lines for so long. 😭
🙈 🙊 🙉
config/log.conf
Outdated
| @@ -1,4 +1,4 @@ | |||
| log_format main '$remote_addr - $remote_user [$time_local] $status ' | |||
| log_format main '$remote_addr - $remote_user [$time_local] $status ' | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed because I think this was left here by mistake. Not easy to spot so it could have easily been missed.
config/log.conf
Outdated
| '"body_bytes_sent":"$body_bytes_sent",' | ||
| '"http_referrer":"$http_referer",' | ||
| '"http_user_agent":"$http_user_agent",' | ||
| '"http_x_forwarded_for":"$http_x_forwarded_for",' | ||
| '"proxy_x_request_id":"$proxy_x_request_id",' | ||
| '"remote_addr":"$remote_addr",' | ||
| '"remote_user":"$remote_user",' | ||
| '"request":"$request",' | ||
| '"request_length":"$request_length",' | ||
| '"request_time":"$request_time",' | ||
| '"status": "$status",' | ||
| '"time_local":"$time_local"' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To note, the last attribute has no ,. Also; two questions:
- Is there anything we'd like to add?
- Is there anything we'd like to rename?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added $host, $proxy_x_forwarded_port, $proxy_x_forwarded_proto and $proxy_x_forwarded_ssl in 05abb67.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's probably okay for now.
That may be useful for debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested just in case there are syntax errors ...
$ docker-compose up -d
Creating network "docker-nginx-proxy_local" with the default driver
Creating docker-nginx-proxy_app_1 ... done
Creating docker-nginx-proxy_proxy_1 ... done
$ docker-compose ps
Name Command State Ports
----------------------------------------------------------------------------------------------------
docker-nginx-proxy_app_1 caddy run --config /etc/ca ... Up 2019/tcp, 443/tcp, 80/tcp
docker-nginx-proxy_proxy_1 /docker-entrypoint.sh ngin ... Up 80/tcp, 0.0.0.0:8080->8080/tcp
$ curl -I http://0.0.0.0:8080
HTTP/1.1 200 OK
Date: Wed, 10 Feb 2021 12:31:06 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 12226
Connection: keep-alive
Accept-Ranges: bytes
Etag: "qlhhmd9fm"
Last-Modified: Thu, 17 Dec 2020 12:35:01 GMT
X-Robots-Tag: "noindex, nofollow"
$ docker-compose logs -f proxy
Attaching to docker-nginx-proxy_proxy_1
proxy_1 | {"body_bytes_sent":"0","host":"0.0.0.0","http_referrer":"","http_user_agent":"curl/7.73.0","http_x_forwarded_for":"","proxy_x_forwarded_port":"8080","proxy_x_forwarded_proto":"http","proxy_x_forwarded_ssl":"off","proxy_x_request_id":"fc4fa2bfb7b54ec917a462d6c9bb5442","remote_addr":"172.18.0.1","remote_user":"","request":"HEAD / HTTP/1.1","request_length":"77","request_time":"0.001","status": "200","time_local":"10/Feb/2021:12:31:06 +0000"}And the output is valid JSON ...
{
"body_bytes_sent": "0",
"host": "0.0.0.0",
"http_referrer": "",
"http_user_agent": "curl/7.73.0",
"http_x_forwarded_for": "",
"proxy_x_forwarded_port": "8080",
"proxy_x_forwarded_proto": "http",
"proxy_x_forwarded_ssl": "off",
"proxy_x_request_id": "fc4fa2bfb7b54ec917a462d6c9bb5442",
"remote_addr": "172.18.0.1",
"remote_user": "",
"request": "HEAD / HTTP/1.1",
"request_length": "77",
"request_time": "0.001",
"status": "200",
"time_local": "10/Feb/2021:12:31:06 +0000"
}
config/log.conf
Outdated
| '"request_length":"$request_length",' | ||
| '"request_time":"$request_time",' | ||
| '"status": "$status",' | ||
| '"time_local":"$time_local"' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way this returns 10/Feb/2021:12:31:06 +000 but there's also $time_iso8601. Thoughts?
$time_iso8601
local time in the ISO 8601 standard format
$time_local
local time in the Common Log Format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Options are:
- We change to
$time_iso8601. - We keep both
$time_iso8601and$time_local.
I'm leaning on the second one so that one can choose what they want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think $time_iso8601 is better as it is more common than CLF. 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL. Ok, changing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to $time_iso8601 in c2b081f.
By doing the following:
mainlogging format tomain_default.$time_local&$statusfrommain_defaultlogging format.main_jsonlogging format and configure it onaccess_logto log in JSON format.See commits for details. Each commit is an idea.