Error using Google Stackdriver Logging in App Engine Standard python

空扰寡人 提交于 2019-12-03 06:49:41

I usually tie the Python logging module directly into Google Stackdriver Logging. To do this, I create a log_helper module:

from google.cloud import logging as gc_logging
import logging

logging_client = gc_logging.Client()
logging_client.setup_logging(logging.INFO)

from logging import *

Which I then import into other files like this:

import log_helper as logging

After which you can use the module like you would the default python logging module.

To create named logs with the default python logging module, use different loggers for different namespaces:

import log_helper as logging

test_logger = logging.getLogger('test')
test_logger.setLevel(logging.INFO)
test_logger.info('is the name of this logger')

Output:

INFO:test:is the name of this logger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!