自定义日志采集上报

本文介绍应用的自定义日志数据如何采集上报到天眼平台。

应用自定义日志上报天眼平台的模式

上报模式

应用自定义日志采集上报实现

应用自定义日志要上报到天眼平台,需要先规划定义好日志结构及日志文件存储地址,再到天眼平台创建配置产品/应用,并获得天眼日志收集器FluentBit的配置参数,用以部署好天眼日志收集器FluentBit,然后应用程序运行时通过日志模块输出运行日志到日志文件,通过FluentBit从日志文件收集日志上报到天眼平台:

1、定义日志结构及日志文件存储路径

应用结合自身业务场景和需求,定义日志数据的结构和格式,日志格式建议:JSON,一行为一条日志,同时定义好日志文件存放路径和命名规则。

日志数据结构定义需要提供给天眼平台,包括字段英文名(JSON里的Key_name)、字段中文名、字段类型、排序等。用于在天眼平台的日志管理里进行属性映射,方便用户在日志管理里查询分析日志。

实例日志文件:/logs/20210412.log

{"log_time":"2020-12-01 17:06:41","log_level":"info","app_uid":"hmzx","app_tcode":"hmzx","category":"sdk.api","log_type":"business","log_content":"{\"url\":\"https:\\\/\\\/app-ykj-test.myfuwu.com.cn\\\/m\\\/Organization\\\/api\\\/get-auth-projects\"}","app_env":"test","app_vid":"834845f36322a313e825ac10b0db4260_1609404744","log_tag":"","app_code":"rental","log_trace":"in \/webser\/www\/eam\/lib\/sdk\/api\/BaseApi.php:185\n in \/webser\/www\/eam\/lib\/sdk\/api\/BaseApi.php:165\n in \/webser\/www\/eam\/lib\/sdk\/bms\/auth\/helper\/ProjectAuthHelper.php:29\n in \/webser\/www\/eam\/rental\/protected\/services\/user\/AdminUserService.php:110\n in \/webser\/www\/eam\/rental\/protected\/domain\/presenters\/workflow\/WorkflowInstancePresenter.php:655\n in \/webser\/www\/eam\/rental\/protected\/domain\/presenters\/workflow\/WorkflowInstancePresenter.php:586\n in \/webser\/www\/eam\/rental\/protected\/domain\/presenters\/workflow\/WorkflowInstancePresenter.php:168"}
{"log_time":"2020-12-01 17:06:41","log_level":"info","app_uid":"hmzx","app_tcode":"hmzx","category":"sdk.api","log_type":"business","log_content":"{\"url\":\"https:\\\/\\\/app-ykj-test.myfuwu.com.cn\\\/m\\\/Organization\\\/api\\\/get-auth-projects\",\"params\":{\"tenant_code\":\"hmzx\",\"user_id\":\"22b11db4-e907-4f1f-8835-b9daab6e1f23\",\"project_mode\":\"all\"}}","app_env":"test","app_vid":"834845f36322a313e825ac10b0db4260_1609404744","log_tag":"","app_code":"rental","log_trace":"in \/webser\/www\/eam\/lib\/sdk\/api\/BaseApi.php:205\n in \/webser\/www\/eam\/lib\/sdk\/api\/BaseApi.php:165\n in \/webser\/www\/eam\/lib\/sdk\/bms\/auth\/helper\/ProjectAuthHelper.php:29\n in \/webser\/www\/eam\/rental\/protected\/services\/user\/AdminUserService.php:110\n in \/webser\/www\/eam\/rental\/protected\/domain\/presenters\/workflow\/WorkflowInstancePresenter.php:655\n in \/webser\/www\/eam\/rental\/protected\/domain\/presenters\/workflow\/WorkflowInstancePresenter.php:586\n in \/webser\/www\/eam\/rental\/protected\/domain\/presenters\/workflow\/WorkflowInstancePresenter.php:168"}

2、在天眼创建并配置产品/应用,获取日志收集器配置参数

应用的自定义日志接入天眼平台,需要在天眼平台开通账号主体,创建团队、产品及对应的应用,同时还需配置日志服务,提供日志收集器FluentBit的配置信息。

说明:因天眼平台暂时未提供对外的日志服务配置定义功能,因此该步骤的工作需要联系天眼平台成员协助处理。

3、部署日志收集器FluentBit

本步骤在应用的运行环境里部署天眼日志收集器FluentBit,在windows环境、容器和星舟(云擎)上部署存在差异,具体参见部署日志收集器Fluentbit

4、应用运行写入日志文件,FluentBit收集上报天眼

应用程序通过日志模块输出运行日志到日志文件,FluentBit从日志文件收集自定义日志数据上报天眼平台,完成自定义日志数据的采集上报过程。

results matching ""

    No results matching ""