Hi guys,
I didn't find in the documentation a way to change the format of the access logs. I would like to change the order and add other fields (e.g. X-Forwarded-For, Host). How can I accomplish that?
Thank you!
It's not possible yet. To add such feature we first need to implement more configuration variables.
@robjr
Hi @hongzhidao,
Thank you for looking into this @hongzhidao , @VBart
@robjr
Just add that there is another format. ${headers.X-Forwarded-For}
Syntax: ${headers.arbitray-head-name}
@robjr
Here's a patch to support the custom log format.
https://gist.github.com/hongzhidao/adecca91feb7179fedadf339ea751894
Please note it's just my personal try, not unit official.
Unit configuration.
access_log: {
"path": "access log file",
"format": "$remote_addr - - [$local_time] \"$request_uri\" $status $bytes_sent \"$http_referer\" \"$http_user_agent\""
}
Now, these variables are avaiable.
$host, $uri, $method, $remote_addr, $local_time, $request_uri,
$status, $bytes_sent, $http_referer, $http_user_agent,
${headers.header name}, ${args.arg name}, ${cookies.cookie name}
Feedbacks are welcome :)
Hi @hongzhidao ,
Awesome, I like this format ${headers.X-Forwarded-For}.
I just tested the patch locally and it is working like a charm. If we can add two other variables to include the HTTP version and another for the request time it would be perfect. After enough testing, I'm wondering if we can include this in one of the next releases. Thank you very much!
If we can add two other variables to include the HTTP version and another for the request time it would be perfect.
metric information, it's a big feature.I'm wondering if we can include this in one of the next releases.
Actually, from my personal impression, all these NGINX open source projects are quite stable, even if development versions.
And they are active with feedback. I'll keep updating the patch in this ticket, you are welcome to merge it in the latest version.
@robjr
Updated.
https://gist.github.com/hongzhidao/adecca91feb7179fedadf339ea751894
Added two variables. $http_version and $request_time. Welcome to test.
Thank you for including the $request_time variable. This is exactly what I was so much missing! Hope it is a part of the stable version soon.
Oh man! This is great. I came here looking to see if Unit could support logging custom formats (ie. outputting JSON like how Nginx does with escape=json).
Any chance more options like this can find its way into stable?
Most helpful comment
@robjr
Here's a patch to support the custom log format.
https://gist.github.com/hongzhidao/adecca91feb7179fedadf339ea751894
Please note it's just my personal try, not unit official.
Unit configuration.
Now, these variables are avaiable.
$host, $uri, $method, $remote_addr, $local_time, $request_uri,
$status, $bytes_sent, $http_referer, $http_user_agent,
${headers.header name}, ${args.arg name}, ${cookies.cookie name}
Feedbacks are welcome :)