[英]Writing python logs to Google Cloud Logging
I have an application running on Google Cloud Compute. 我有一个在Google Cloud Compute上运行的应用程序。
My python logging is currently configured to write to syslog as: 我的python日志记录当前配置为以以下方式写入syslog:
import logging
import logging.handlers
logger = logging.getLogger('pyAdminLogger')
logger.setLevel(logging.DEBUG)
handler = logging.handlers.SysLogHandler(address = '/dev/log')
logger.addHandler(handler)
I've been hunting around for a way to get my logs into the Google Cloud Logging API, but I keep coming up empty handed. 我一直在寻找将日志记录到Google Cloud Logging API中的方法,但是我总是空手而归。
As far as I can see I have two options: 据我所知,我有两个选择:
What I really want is some sort of third option where I can configure the standard python logging to write into the Google Cloud Logging API. 我真正想要的是某种第三种选择,我可以在其中配置标准的python日志记录以写入Google Cloud Logging API。
Those two options are really good. 这两个选择真的很好。 Personally I like installing
google-fluentd
which one can install on an instance and create a template using that instance. 我个人喜欢安装
google-fluentd
,它可以安装在实例上并使用该实例创建模板。 Rest is just using that template to launch any new instances. 其余的只是使用该模板来启动任何新实例。
This frees up codebase responsibility to include and maintain any external libraries. 这释放了代码库负责包括和维护任何外部库的责任。 Moreover if you were to ever switch to another cloud provider you can easily keep writing logs to syslog and stream them out of instance using some other provider.
此外,如果您要切换到其他云提供商,则可以轻松地将日志写入syslog并使用其他提供商将其流出实例。
Other than these options there is also gcloud-python which is provided by cloud team. 除了这些选项之外 ,云团队还提供了gcloud-python 。 Though seems like its not up-to-date with beta apis, logging being one of them.
尽管似乎不是最新的beta api,但日志记录就是其中之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.