Skip to content

Conversation

@itskingori
Copy link
Member

@itskingori itskingori commented Feb 10, 2021

By doing the following:

  • Renamed main logging format to main_default.
  • Remove unnecessary double space between $time_local & $status from main_default logging format.
  • Add main_json logging format and configure it on access_log to log in JSON format.

See commits for details. Each commit is an idea.

@itskingori itskingori requested a review from a team as a code owner February 10, 2021 10:28
@itskingori itskingori force-pushed the log_format_improvements branch from 76e1ea8 to ddd075d Compare February 10, 2021 10:31
Copy link
Member Author

@itskingori itskingori left a 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;
Copy link
Member Author

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!!

Copy link
Member Author

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.

Copy link
Member

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. 😭

Copy link
Member Author

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 '
Copy link
Member Author

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
Comment on lines 8 to 19
'"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"'
Copy link
Member Author

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:

  1. Is there anything we'd like to add?
  2. Is there anything we'd like to rename?

Copy link
Member Author

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.

Copy link
Member

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.
Copy link
Member Author

@itskingori itskingori left a 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"'
Copy link
Member Author

@itskingori itskingori Feb 10, 2021

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Options are:

  1. We change to $time_iso8601.
  2. We keep both $time_iso8601 and $time_local.

I'm leaning on the second one so that one can choose what they want.

Copy link
Member

@zacblazic zacblazic Feb 10, 2021

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. 😬

Copy link
Member Author

Choose a reason for hiding this comment

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

LOL. Ok, changing.

Copy link
Member Author

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.

@itskingori itskingori merged commit 2c9b4cb into master Feb 10, 2021
@itskingori itskingori deleted the log_format_improvements branch February 10, 2021 13:55
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