我在Google Cloud Compute上运行了一个应用程序。
我的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)我一直在寻找一种方法来获取我的日志到Google Cloud Logging API,但我一直空手而归。
据我所知,我有两个选择:
使用Google SDK编写日志(我真的不想将其添加为对我的代码的依赖) 在我的所有实例上安装google-fluentd,以便它可以在系统日志中运行。我真正想要的是某种第三种选择,我可以配置标准的python日志记录来写入Google Cloud Logging API。
I have an application running on Google Cloud Compute.
My python logging is currently configured to write to syslog as:
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.
As far as I can see I have two options:
Use the Google SDK to write logs (I really don't want to add this as a dependency on my code) Install google-fluentd on all my instances so that it can steam the 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.
最满意答案
这两个选项真的很棒。 我个人喜欢安装google-fluentd ,可以在实例上安装并使用该实例创建模板。 Rest只是使用该模板来启动任何新实例。
这释放了代码库的责任,包括和维护任何外部库。 此外,如果您要切换到另一个云提供程序,您可以轻松地将日志写入syslog,并使用其他提供程序将其流出实例。
除了这些选项之外,还有由云团队提供的gcloud-python 。 虽然它似乎与beta apis不是最新的,但日志记录就是其中之一。
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. 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.
Other than these options there is also gcloud-python which is provided by cloud team. Though seems like its not up-to-date with beta apis, logging being one of them.
将python日志写入Google Cloud Logging(Writing python logs to Google Cloud Logging)我在Google Cloud Compute上运行了一个应用程序。
我的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)我一直在寻找一种方法来获取我的日志到Google Cloud Logging API,但我一直空手而归。
据我所知,我有两个选择:
使用Google SDK编写日志(我真的不想将其添加为对我的代码的依赖) 在我的所有实例上安装google-fluentd,以便它可以在系统日志中运行。我真正想要的是某种第三种选择,我可以配置标准的python日志记录来写入Google Cloud Logging API。
I have an application running on Google Cloud Compute.
My python logging is currently configured to write to syslog as:
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.
As far as I can see I have two options:
Use the Google SDK to write logs (I really don't want to add this as a dependency on my code) Install google-fluentd on all my instances so that it can steam the 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.
最满意答案
这两个选项真的很棒。 我个人喜欢安装google-fluentd ,可以在实例上安装并使用该实例创建模板。 Rest只是使用该模板来启动任何新实例。
这释放了代码库的责任,包括和维护任何外部库。 此外,如果您要切换到另一个云提供程序,您可以轻松地将日志写入syslog,并使用其他提供程序将其流出实例。
除了这些选项之外,还有由云团队提供的gcloud-python 。 虽然它似乎与beta apis不是最新的,但日志记录就是其中之一。
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. 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.
Other than these options there is also gcloud-python which is provided by cloud team. Though seems like its not up-to-date with beta apis, logging being one of them.
发布评论