<p>I want to see logs on stack driver/google logging per http request.
Currently, I get all the logs but with so many pods I can't correlate with which log belongs to which request.</p>

<p>On appengine every log entry is per http request by default and contains nested logs from the same request.</p>

<p>I am using gunicorn with python if that's helping.</p>

<p>If that's helping, that's how i write logs:</p>

<pre><code>def set_logging_env(app):
    logging.basicConfig(format='', level=logging.INFO)
    if __name__ != '__main__':
        gunicorn_logger = logging.getLogger('gunicorn.info')
        app.logger.handlers = gunicorn_logger.handlers
        app.logger.setLevel(gunicorn_logger.level)
</code></pre>

Oren Lalezari
<p>There are some option to customize your logging patterns.
First I would suggest getting familiar with the basics from the official documentations <a href="https://kubernetes.io/docs/concepts/cluster-administration/logging/" rel="nofollow noreferrer">here</a>.</p>

<p>Than there is a general guide regarding <a href="https://kubernetes.io/docs/tasks/debug-application-cluster/logging-stackdriver/" rel="nofollow noreferrer">logging with stackdriver</a>.</p>

<p>There we have:</p>

<blockquote>
  <p>Stackdriver Logging agent attaches metadata to each log entry, for you
  to use later in queries to select only the messages you’re interested
  in: for example, the messages from a particular pod.</p>
</blockquote>

<p>Which is one of the things you seek I suppose.</p>

<p>Finally you can use follow <a href="https://cloud.google.com/logging/docs/view/overview" rel="nofollow noreferrer">this guide</a> to know how to view logs and later <a href="https://cloud.google.com/logging/docs/view/advanced-filters" rel="nofollow noreferrer">this one</a> to setup advanced filters:</p>

<blockquote>
  <p>This guide shows you how to write advanced logs filters, which are
  expressions that can specify a set of log entries from any number of
  logs. Advanced logs filters can be used in the Logs Viewer, the
  Stackdriver Logging API, or the command-line interface.</p>
</blockquote>

<p>Also if you want to check logs from the running pods from the Kubernetes level you can use this <a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/#interacting-with-running-pods" rel="nofollow noreferrer">cheatsheet</a>.</p>

<pre><code>kubectl logs my-pod                                 # dump pod logs (stdout)
kubectl logs -l name=myLabel                        # dump pod logs, with label name=myLabel (stdout)
kubectl logs my-pod --previous                      # dump pod logs (stdout) for a previous instantiation of a container
kubectl logs my-pod -c my-container                 # dump pod container logs (stdout, multi-container case)
kubectl logs -l name=myLabel -c my-container        # dump pod logs, with label name=myLabel (stdout)
kubectl logs my-pod -c my-container --previous      # dump pod container logs (stdout, multi-container case) for a previous instantiation of a container
kubectl logs -f my-pod                              # stream pod logs (stdout)
kubectl logs -f my-pod -c my-container              # stream pod container logs (stdout, multi-container case)
kubectl logs -f -l name=myLabel --all-containers    # stream all pods logs with label name=myLabel (stdout)
</code></pre>

<p>I hope I understood you correctly and my answer would be valuable.
Please let me know if that helped.</p>
