title: Symfony2 monolog logger custom fields in symfony command exec
body: <p><strong>Situation:</strong></p>
  
  <p>In my Symfony2.8 API, I have a custom RecordProcessor for Monolog, in which I added some convenient informations:</p>
  
  <pre><code>my_api.logger.formatter:
      class: Monolog\Formatter\LineFormatter
      arguments:
          - "[%%datetime%%] [%%extra.request_id%%] [%%extra.ip%%] [%%extra.user%%] %%channel%%.%%level_name%%: %%message%% %%context%%\n"
  </code></pre>
  
  <p>As you can see, I add to every request (common practice I guess) a unique execution Uuid (request_id) to the headers of the request in front controllers (web/app.php). So here is what my logs lines look like:</p>
  
  <pre><code>[2017-10-27 13:11:24] [7e1666b7] [79.XX.XX.XX] [myuser@gmail.com] app.INFO: OutGoing GET ...
  [2017-10-27 13:11:24] [15ded457] [11.XX.XX.XX] [myotheruser@gmail.com] security.DEBUG: ... 
  [2017-10-27 13:11:24] [15ded457] [11.XX.XX.XX] [myotheruser@gmail.com] security.DEBUG: ...
  [2017-10-27 13:11:24] [15ded457] [11.XX.XX.XX] [myotheruser@gmail.com] app.INFO: Incoming POST ...
  [2017-10-27 13:11:24] [15ded457] [44.XX.XX.XX] [myotheruser@gmail.com] app.INFO: Asynchronous : SENDING message ....
  </code></pre>
  
  <p>I use rabbitmq with rabbitmq-bundle and phpamqplib for async heavy logic processing. This works with rabbitmq consumers launched thanks to symfony commands (and rabbitmq-supervisord-bundle). These rabbitmq consumers log stuff to the common log file of the app (/var/log/env.log). </p>
  
  <p><strong>Problem:</strong></p>
  
  <p>I would like to add a unique_id to the log lines of the consummer processes (from symfony commands, as the processes are async by nature, and some async processes launch other async processes, log file is unreadable...). 
  How to do so ? I've found a lot of doc on monolog handlers, but it seems that its not what I'm looking for. I also tried creating a fake request with my uniqueId header, pushed onto the stack_request (as in classic http trait), but this seems ugly and too faky.</p>
  
  <p>Ideally, I'd like to do this, in my abstract GenericMyAppConsumer.php:</p>
  
  <pre><code>//Constructor of any consumers (sf command)
  //...
  $this-&gt;container-&gt;get('logger')-&gt;setData('extra.request_id', $this-&gt;uniqueId);
  </code></pre>
  
  <p>So it will be used for all the current thread logging.</p>
  
  <p>I hope I'm clear. 
  Thanks.</p>