将日志写入云日志或fluentd,用于gcp中的app

gcp-mixed-logging的Python项目详细描述


GCP混合对数

GCP混合日志。在

入门

从PyPI安装

pip install gcp-mixed-logging

云记录

使到,Python版Cloud Logging,权限参见官方文档

Tips: 在本地和其他位置运行时, 需要使用Service Account或下方Auth说明中的第2种方法.

Fluentd

支持持久化志转发布至Fluentd或Fluent Bit。在

Fluentd/Fluent位方式:

美国石油学会

总结

{$str}混合^类_日志记录.MixedLogging

from gcp_mixed_logging import MixedLogging

成员:

  • cloudlogging_name:云登录路径
  • 你还活着吗
methodabount
close()停止接收日志, 缓存中日志写入Cloud Logging / Fluentd
debug(msg)诊断日志, msg: str or dict
info(msg)msg: str or dict
warning(msg)msg: str or dict
error(msg)msg: str or dict
metric(..)todo
persist(tag, msg)持久化日志, 转发至Fluent

混合记录(模块:str,阶段:str…)

Param

  • module:str:模块或子模块名称
  • 阶段:str:stage,dev/test/prod/。。。在
  • fluent_host:str='localhost',fluentd主机ip或dns
  • fluent_端口:int=24224,fluentd forward port
  • 项目:str=None,项目名称,如果没有,则从默认身份验证读取
  • scopes:可选[Collection[str]=\u DEFAULT_scopes,默认身份验证的作用域
  • 资源:resource=\u GLOBAL_resource,云日志资源

调试/信息/警告/错误(消息:任何)

Send message to Cloud Logging in background thread, append information:

  • labels: module/stage/host
  • jsonPaylod: filename/function/lineno of caller frame Param: msg: Any, text or dict message

持续(tag:str,msg:dict,track:bool=False,track_严重性:str=“DEFAULT”,**kw)

Foward message to Fluent in background thread, append information:

  • host/timestamps
  • insert_id: increment intger per tag per host

Param

  • tag:str,fluent的标记名
  • msg:dict,dict类型的有效负载数据
  • track:bool=False,两个track-to-cloud日志记录
  • track_severity:str=“DEFAULT”,云日志记录的严重性

示例

^{pr2}$

更多

谷歌认证

请参阅google.auth

  1. 如果环境变量GOOGLE_APPLICATION_CREDENTIALS设置为有效服务帐户JSON私钥文件的路径,则加载并返回该文件。返回的项目ID是在服务帐户文件中定义的项目ID(如果可用)(某些旧文件不包含项目ID信息)。在

  2. 如果安装了Google Cloud SDK},并且设置了应用程序默认凭据,则加载并返回这些凭据。在

    要使用云SDK启用应用程序默认凭据,请运行:gcloud auth application-default login

    如果云SDK有活动项目,则返回项目ID。可以使用以下命令设置活动项目:gcloud config set project

  3. 如果应用程序正在App Engine standard environment中运行,则使用来自App Identity Service的凭据和项目ID。在

  4. 如果应用程序在Compute EngineApp Engine flexible environment中运行,则凭据和项目ID将从Metadata Service中获取。在

  5. 如果找不到凭据, :类:~google.auth.exceptions.DefaultCredentialsError将被引发。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何从通知中获取图像?   java按住按钮将循环一个动作,直到它被释放   JavaJavassist:如何将动态生成的类添加到特定的包中?   java我需要获取一个字符串并输出字符串中出现最多的单词   java合并排序堆栈溢出错误   java如何使用spring boot配置hibernate   Android中带选择器的Java TCP服务器NIO   java对于长度急剧变化的输入,什么是最佳的StringBuffer初始容量?   java SpringBoot:REST endpint中@RequestParam参数的自定义验证   JavaJPaQuery。fetchResults()已弃用,应如何替换它?   JavaJNA结构创建带来麻烦   java创建只包含响应中某些元素的POJO   java巨大的Perm Gen与应用程序大小相比,是否正常?   JavalibgdxMoveToAction。将setPosition()设置为负坐标,以将演员移出舞台