简体   繁体   English

Google Cloud日志记录,将Python与Docker容器一起使用

[英]Google cloud logging, using python with docker container

I have simple python app and want to use google cloud logging. 我有简单的python应用程序,想使用Google云日志记录。 I use docker and run it with kubernetes. 我使用docker并使用kubernetes运行它。

How can i send the logs to google cloud logging? 如何将日志发送到Google云日志?

import time
import logging

def main():
    logging.basicConfig()
    logging.getLogger().setLevel(logging.INFO)
    try:
        while True:
            logging.info('Working...')
            time.sleep(1)
    except KeyboardInterrupt:
        logging.info('Stopped working')
        pass;

if __name__ == '__main__':
    main()

If you configure your logger to write to stdout, Kubernetes will automatically send it to Google Cloud Logging for you. 如果您将记录器配置为写入标准输出,Kubernetes将自动为您将其发送到Google Cloud Logging。

Otherwise you'll have to use a sidecar container to collect the logs and upload them for you, like in this example . 否则,您将不得不使用sidecar容器来收集日志并为您上传日志,如本示例所示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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