Cubox
(Andy Pilate)
November 22, 2020, 7:58pm
1
Hi,
I’m switching to Caddy from nginx, and I’m trying to replicate its behaviour in many parts in order to keep my habits. One area where I’m not happy is access logs. Either single_field common_log, which is too little, or full json, which is difficult to read.
How could I get an access log output like the one with default nginx?
'$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent"'
Even if some of those fields are not possible to get (body bytes sent), everything else is present in the json. Help is really appreciated
You can use this plugin to make a custom log encoding based on the fields provided in the JSON:
/cc @Mohammed90 in case you have any tips to add
1 Like
Mohammed90
(Mohammed Al Sahaf)
November 23, 2020, 11:53pm
3
For reference, this is a sample of the JSON log message:
JSON
{
"request": {
"remote_addr": "[::1]:60457",
"proto": "HTTP/2.0",
"method": "GET",
"host": "localhost",
"uri": "/",
"headers": {
"User-Agent": [
"Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0"
],
"Accept": [
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
],
"Accept-Language": [
"en-US,en;q=0.5"
],
"Upgrade-Insecure-Requests": [
"1"
],
"Accept-Encoding": [
"gzip, deflate, br"
],
"Te": [
"trailers"
]
},
"tls": {
"resumed": false,
"version": 772,
"cipher_suite": 4865,
"proto": "h2",
"proto_mutual": true,
"server_name": "localhost"
}
},
"common_log": "::1 - mohammed [24/Nov/2020:02:26:15 +0300] \"GET / HTTP/2.0\" 200 83676",
"duration": 1.065969691,
"size": 83676,
"status": 200,
"resp_headers": {
"Server": [
"Caddy"
],
"Content-Type": [
"text/html; charset=utf-8"
]
}
}
Note that replacing placeholders of not present values with -
(or whatever string you want) is implemented in master’s latest commit, but not part of a released tag yet.
system
(system)
Closed
December 22, 2020, 7:58pm
4
This topic was automatically closed after 30 days. New replies are no longer allowed.