How to set the property requestAttributesEnabled for AccessLogValve in Apache Tomcat, in a spring-boot application?
<p>We have a standalone spring-boot application, where we want to set access log pattern such that</p>

<ul>
<li><em>X-forwarded-for</em> header exists in request: It should be included in the logs as the first field</li>
<li><em>X-forwarded-for</em> header DOESN'T exists in request: It should be replaced by remote ip address</li>
</ul>

<p>When we run our application with the following settings, we only get remote ip address</p>

<pre><code>server.tomcat.accesslog.directory=&lt;path_to_log_director&gt;
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b
server.tomcat.accesslog.prefix=access_log
server.tomcat.accesslog.suffix=.log
</code></pre>

<p>eg: </p>

<pre><code>192.168.25.265 - - - [12/Sep/2016:10:20:56 +0200] "GET /myapp HTTP/1.1" 200 125922
</code></pre>

<p>We also tried to set property server.tomcat.accesslog.pattern to </p>

<pre><code>%h %{X-Forwarded-For}i %l %u %t "%r" %s %b
</code></pre>

<p>then we get both remote ip address and X-forwarded-for header value.</p>

<p>eg:</p>

<pre><code>192.168.25.265 192.168.21.65 - - - [12/Sep/2016:10:20:56 +0200] "GET /myapp HTTP/1.1" 200 125922
</code></pre>

<p>However, based on the link <a href="https://tomcat.apache.org/tomcat-7.0-doc/config/valve.html" rel="nofollow noreferrer">https://tomcat.apache.org/tomcat-7.0-doc/config/valve.html</a>, tomcat supports this requirement to include remote ip address when x-forwarded-for doesn't exist. This can be achieved by adding the property 'requestAttributesEnabled'</p>

<p>We tried adding the property 
    server.tomcat.accesslog.requestAttributesEnabled 
but no effect took place.</p>

<p>It doesn't appear to be implemented since it's not present here: <a href="http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html" rel="nofollow noreferrer">http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html</a></p>

<p>We implemented a workaround using an implementation of EmbeddedServletContainerCustomizer, as mentioned in <a href="https://stackoverflow.com/questions/28483064/how-do-i-configure-the-location-and-name-of-tomcat-access-log-in-spring-boot">How do I configure the location and name of tomcat access log in spring-boot?</a>,
where we added:</p>

<pre><code>accessLogValve.setRequestAttributesEnabled(true);
</code></pre>

<p>and it worked as expected.</p>

<p>However we would prefer to be able to set the requestAttributesEnabled as a configuration property through spring-boot, like:</p>

<pre><code>server.tomcat.accesslog.requestAttributesEnabled=true
</code></pre>

<p>rather than have the need to use this customizer in all our services.</p>

<p>Is there a better solution to this problem, is there another property to be used, or is it a feature that can be expected to be delivered in the near future?</p>