Search code examples
pythonlogginggoogle-cloud-platformstackdriver

Python logging to GCP StackDriver missing log-type icon


I'm using this approach for sending logs from my GCP App-Engine logic to GCP Stackdriver logging:

import logging
import google.cloud.logging
from google.cloud.logging.handlers import CloudLoggingHandler, setup_logging

client = google.cloud.logging.Client()
handler = CloudLoggingHandler(client)
logging.getLogger().setLevel(logging.INFO) 
setup_logging(handler)

logging.info('just info')
logging.warning('warning info')
logging.error('bad news')

This works and produces logs that are all classified generically and look like this:

no-icon log entries

However what I'd like to see is the same log but with the associated severity level classification and visually having log-level classification icon, like this in example:

good-icon log entry

I've been going through the documentation found here and tried a number of things but all with the same no-icon result. Any advice or recommendations welcome.


Solution

  • After researching the issue and following a number of dead-end leads I happened across this site which provided me a working answer:

    https://blog.frank-mich.com/python-logging-to-stackdriver/

    In short I followed his solution using the Stackdriver formatting via the StreamHandler. This now allows me to produce proper SEVERITY level formatted log entries that can be properly filtered in GCP Logging:

    enter image description here