Error using Google Stackdriver Logging in App Engine Standard python

后端 未结 1 1234
滥情空心
滥情空心 2021-02-08 05:30

My Stack:
Google App Engine Standard
Python (2.7)

Goal:
To create named logs in Google Stackdriver Logging, https:/

相关标签:
1条回答
  • 2021-02-08 05:34

    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

    0 讨论(0)
提交回复
热议问题