# Conditional access log formatting?

**URL:** <https://www.ruby-forum.com/t/conditional-access-log-formatting/242709>\
**Category:** NGINX\
**Created:** [July 18, 2015, 12:38pm UTC](https://www.ruby-forum.com/t/conditional-access-log-formatting/242709 "2015-07-18T12:38:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [July 18, 2015, 12:38pm UTC](https://www.ruby-forum.com/t/conditional-access-log-formatting/242709/1 "2015-07-18T12:38:26Z")

</div>

Hi,

I’m using haproxy infront of some NGINX instances, but only for some  
instances which are being loadbalanced by haproxy, there are other  
instances which go straight through.

I realise I need to change the logging format in NGINX to enable  
X-Forwarded-For in the access logs.

The question is whether I can conditionally format the logs, i.e. use  
“X-Forwarded-For” if it exists, otherwise use the normal NGINX logging  
format.

I’ve had a quick peek at the manual, I’m thinking maybe this can be done  
with a map of some sort ? Maybe there’s a better way ? To be honest  
I’ve no idea where to start, and I’ve never used maps before anyway !
