Gatmando
Gatmando

Reputation: 2269

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.

Upvotes: 1

Views: 242

Answers (2)

Gatmando
Gatmando

Reputation: 2269

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

Upvotes: 1

Christian Bonhomme
Christian Bonhomme

Reputation: 45

What you will have to do is set log severity for each of these entries. So for 'just info' for example, you would set the severity to 'info' which will give you that little blue square that shows in you example. Check out this link to see all the levels of severity and what they mean.

Upvotes: 1

Related Questions