title: nginx module to set variable value for log module
body: <p>I want to define an nginx variable, set its value during a request, and use the variable inside a log format.</p>
  
  <p>I am currently implementing a custom module in C (not interested in LUA at the moment).</p>
  
  <p><strong>Desired flow:</strong><br>
   1. configure new log format: <code>log_format my_format '$my_var1';</code> (nginx.conf)<br>
   2. configure new access log using that format: <code>access_log /tmp/out my_format</code> (nginx.conf)<br>
   3. set value during request handler, function from the following type:<br>
   <code>typedef ngx_int_t (*ngx_http_handler_pt)(ngx_http_request_t *r);</code>   </p>
  
  <p><strong>Current flow:</strong><br>
  1. Set variable to an initial value: <code>set $my_var1 'empty_value';</code>  (nginx.conf)<br>
  2. Find variable by index with <code>ngx_http_get_flushed_variable(r, index)</code><br>
  3. Change variable value by assigning to data field.  </p>
  
  <p>When I print my variable to the debug log, I see the variable is set correctly to the changed value. <strong>However</strong>, the log module outputs the initial variable value instead of the changed value to the custom access log.</p>
  
  <p>Can someone point me to what am I missing here?<br>
  Should I use <code>ngx_http_add_variable</code> function or use script compile /complex ?  </p>
  
  <p>short snippet from the current flow described above:</p>
  
  <pre><code>ngx_http_variable_value_t *v;
  v = ngx_http_get_flushed_variable(r, ale_srv_cf-&gt;output_variable_index);
  // ... error handling if not found ....
  v-&gt;data = new_value;
  v-&gt;len = new_value_length;
  
  </code></pre>