title: How to control fluentd log tag from Docker
body: <p>Current setup is running Docker containers with the <code>fluentd</code> driver:</p>
  
  <pre><code>docker run --log-driver=fluentd my-container
  </code></pre>
  
  <p>That works quite easily...sends stdout to the locally running fluentd system on the host.</p>
  
  <p>I'd like to control the fluentd <code>tag</code> using some of the labels which are set on the container.  For this example, assume some labels (<code>docker inspect</code> snippet):</p>
  
  <pre><code>"Config": {
      "Labels": {
         "com.amazonaws.ecs.container-name": "web",
         "com.amazonaws.ecs.task-definition-version": "3"
      }
  }
  </code></pre>
  
  <p>How can I set the <code>fluentd</code> <code>tag</code> by extracting out one or more of the <code>Labels</code>?</p>
  
  <p>The Docker docs on this list out the currently supported tags: <a href="https://docs.docker.com/engine/admin/logging/log_tags/" rel="nofollow">https://docs.docker.com/engine/admin/logging/log_tags/</a></p>
  
  <p>Those docs make note of <code>ExtraAttributes</code>...however I can figure out how to use that to look up one or more labels.  Reading through the Docker code it's not clear to me: <a href="https://github.com/docker/docker/blob/master/daemon/logger/context.go#L29" rel="nofollow">https://github.com/docker/docker/blob/master/daemon/logger/context.go#L29</a></p>
  
  <p>This is trivial to do with <code>docker inspect</code>:</p>
  
  <pre><code>docker inspect --format '{{index .ContainerLabels "com.amazonaws.ecs.container-name"}}'
  </code></pre>
  
  <p>I'd like to grep out the same information and get it into <code>log-opt tag=?</code></p>