Jorden van Breemen
Jorden van Breemen

Reputation: 251

GAE flexible and Stackriver log severity levels with python

I'm running a python 3 application in the google flexible app engine. I'm using the default python root logger and would like to be able to view the log levels like in this image.

When deploying an application with the following log configuration in GAE using gunicorn:

import logging

logging.basicConfig(level=logging.INFO)
logging.warn('Warning level message')

All log levels show up under any log level in GAE independent of the severity level.

I tried using the Stackdriver logging client for python:

import logging
from google.cloud import logging as gcloud_logging

client = gcloud_logging.Client()
client.setup_logging(logging.INFO)

logging.basicConfig(level=logging.INFO)
logging.warn('Warning level message')

When executing locally this logs to Stackdriver (under 'global') with the log levels actually functioning properly. However, when I deploy this application in the GAE the log levels of the GAE still show up under 'any log level'. Also, the logging under 'global' does not seem to function.

Is there an easy way to get the log severity levels to work with the google standard app engine with python 3?

Upvotes: 4

Views: 283

Answers (1)

Dustin Ingram
Dustin Ingram

Reputation: 21580

Have you tried integrating the Stackdriver Logging with the Python logging module?

From https://gcloud-python.readthedocs.io/en/latest/logging/usage.html#integration-with-python-logging-module:

import logging
handler = client.get_default_handler()
cloud_logger = logging.getLogger('cloudLogger')
cloud_logger.setLevel(logging.INFO)
cloud_logger.addHandler(handler)
cloud_logger.error('bad news')

Upvotes: 1

Related Questions