title: Using docker GELF driver env/labels in logstash
body: <p>Docker GELF log driver allows <code>env</code> and <code>labels</code> log-opts:</p>
  
  <blockquote>
    <p>The labels and env options are supported by the gelf logging driver. It adds additional key on the <strong>extra</strong> fields, prefixed by an underscore (_) (<a href="https://docs.docker.com/engine/admin/logging/overview/#/gelf-options" rel="noreferrer">ref</a>)</p>
  </blockquote>
  
  <p>I want to use this in my index name for elasticsearch output but I couldn't figure out how I can access these value or said <code>extra</code> fields.</p>
  
  <p>Assuming that I have these options running a container,</p>
  
  <pre><code>docker run -it \
    --log-driver gelf \
    --log-opt gelf-address=udp://127.0.0.1:12201 \
    --log-opt tag=some-app \
    --log-opt env=staging \
    --log-opt labels=staging \
    ubuntu:16.04 /bin/bash -c 'echo Hello World'
  </code></pre>
  
  <p>I'd like to use the <code>env</code> value that I passed in my logstash config as such:</p>
  
  <pre><code>input {
    gelf { }
  }
  
  output {
    elasticsearch {
      hosts =&gt; ["http://127.0.0.1:9200"]
      index =&gt; "logstash-%{env-value-here}-%{tag}-%{+YYYY.MM.dd}"
    }
  }
  </code></pre>
  
  <p>There seems to be another question about env/labels with Graylog: <a href="https://stackoverflow.com/questions/40030555/docker-gelf-driver-env-option">Docker GELF driver env option</a></p>