集成 SLS SDK 到 HarmonyOS NEXT 应用分为安装和初始化两步:
安装:在项目的 entry 或 library 目录下执行 ohpm install @aliyunsls/producer --registry=https://ohpm.openharmony.cn/ohpm。安装成功后 oh-package.json5 中会自动添加 @aliyunsls/producer 依赖。
初始化:在 ets 文件中导入 AliyunLog 模块,然后创建实例传入 endpoint(Region 域名)、project、logstore、accesskey id、accesskey secret(STS 场景还需 token)。
发送日志:调用 aliyunLog.addLog(new Map([[key, value]])) 即可上报业务字段。
前置条件包括开通 SLS、创建 Project/Logstore、获取 AccessKey(建议使用 RAM 子账号授权)。SDK 通过 OpenHarmony 三方库中心托管发布。




