简体   繁体   中英

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:

无图标日志条目

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 日志条目

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.

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.

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:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM