将日志写入云日志或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:云登录路径
- 你还活着吗
method | abount |
---|---|
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
:
- 在
如果环境变量
在GOOGLE_APPLICATION_CREDENTIALS
设置为有效服务帐户JSON私钥文件的路径,则加载并返回该文件。返回的项目ID是在服务帐户文件中定义的项目ID(如果可用)(某些旧文件不包含项目ID信息)。在 - 在
如果安装了
Google Cloud SDK
},并且设置了应用程序默认凭据,则加载并返回这些凭据。在要使用云SDK启用应用程序默认凭据,请运行:
gcloud auth application-default login
如果云SDK有活动项目,则返回项目ID。可以使用以下命令设置活动项目:
在gcloud config set project
- 在
如果应用程序正在
在App Engine standard environment
中运行,则使用来自App Identity Service
的凭据和项目ID。在 - 在
如果应用程序在
在Compute Engine
或App Engine flexible environment
中运行,则凭据和项目ID将从Metadata Service
中获取。在 - 在
如果找不到凭据, :类:
在~google.auth.exceptions.DefaultCredentialsError
将被引发。在
- 项目
标签: