简体   繁体   English

将python日志写入Google Cloud Logging

[英]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: 据我所知,我有两个选择:

  1. Use the Google SDK to write logs (I really don't want to add this as a dependency on my code) 使用Google SDK编写日志(我真的不想添加它作为对我的代码的依赖)
  2. Install google-fluentd on all my instances so that it can steam the syslog. 在我所有的实例上安装google-fluentd,以便它可以启动syslog。

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.

相关问题 将 python 中使用的库的日志发送到谷歌云堆栈驱动程序日志记录 - Send logs of libraries used in python to google cloud stackdriver logging 记录 Python 和 Google Cloud - Logging Python and Google Cloud Google Cloud trace + Gcloud 登录日志查看器 - Google cloud trace + Gcloud logging in logs viewer 如何在单个 Python 应用程序中分离 Google Cloud Logging 中的日志? - How can I separate logs in Google Cloud Logging within a single Python application? TypeError 从云端将结构化日志写入谷歌云日志 function - TypeError writing a structured log to google cloud logging from a cloud function 无法使用谷歌云日志记录在python3标准环境的谷歌应用引擎中打印相关日志的模块名称和行号 - Unable to print module name and line number for correlated logs in google app engine fo python3 standard environment using google cloud logging 适用于Docker的Google Cloud日志记录驱动程序不收集日志 - Google Cloud logging driver for docker doesn't collect logs Google Cloud Stackdriver 忽略 Python 日志中的格式 - Google Cloud Stackdriver ignores formatting in Python logs 在 Python 单元测试中修补或模拟 Google Cloud Logging - Patch or Mock Google Cloud Logging in Python unittests 谷歌云日志python脚本权限错误 - Google cloud logging python script permission error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM