import insightLogger from './index'; // 仅限于本地开发时使用 // import { ElasticsearchTransport } from './index'; // import axios from 'axios'; // insightLogger.add(new ElasticsearchTransport({ // async request(uploadData) { // await axios({ // method: 'post', // url: 'https://iot.cloud.tencent.com/insight-v2/event', // data: uploadData, // proxy: { // host: '127.0.0.1', // port: 8888, // }, // }); // }, // })); insightLogger.updateGetReportData(() => ({ app: '应用名', // iot-weapp 等 event: '事件名', // 业务自行约定,可以以点号(.)分层级以便筛选 level: '日志等级', metric: { kk1: 'check', type: '指标类型,取值 visit,start,end,success,fail,timeout,若有则可以根据事件名进行通用的 成功率/PV/UV/计数 统计分析', timeCost: 1000, // 耗时(比如 CGI 的耗时,某个业务步骤的耗时等,一般出现在 success,fail,timeout 等指标事件中 oh: 'no', }, // 上下文字段,用于筛选检索(不需要开启分词,支持全等匹配即可,各字段均可选) context: { // 通用上下文 appVersion: '3.9.1', // app 的版本 wxVersion: '8.0.25', // 微信版本(仅小程序) mpLibVersion: '2.25.2', // 小程序基础库版本(仅小程序) uin: '用户 ID', lid: '应用生命周期 ID', anonymousId: '12321', // 业务上下文 productId: '产品 ID', deviceName: '设备名称', // 传 deviceId 自动展开为两个字段 bleDeviceId: '蓝牙设备 ID', flowId: '流程 ID,比如页面生命周期、配网、蓝牙绑定', reqId: '请求 ID', }, data: '事件的明细数据 JSON', // message: '可读的日志描述文本', at: +new Date(), // 当前日志的生成时间(必须有,否则 kibana 里面查询不到这条日志,若缺少该字段则自动填写为上报时间) born: +new Date(), // 当前 lid 的启动时间,若有会自动计算 life = at - born stack: 'JS 堆栈信息', // 可选,若有,可以结合 app + agent.version 检索 sourcemap,可以用于定位 error-log 等非主动上报的日志/异常 })); const bluetoothAdapter = insightLogger.derive(() => ({ event: 'ble', metric: { k1: 'k1', timeCost: 400, metric: { a: 1 }, }, context: { wxVersion: '8.0.96', }, })); const bluetoothAdapter2 = bluetoothAdapter.derive(() => ({ event: 'standard.*', metric: { k2: 'k2', timeCost: 900, }, })); console.log('start'); bluetoothAdapter2.warn('kk2', { message: 'oh no', metric: { metric: { b: 1 }, timeCost: 300, }, context: { appVersion: '3.9.2', }, }); bluetoothAdapter2.event('custom').info('k1', null, { a: 1, context: { b: 12 } }); // bluetoothAdapter2.warn('kk3', 'yes yes yes'); // bluetoothAdapter2.warn('kk4', 'delay no more'); // bluetoothAdapter2.emerg('kk5', 'delay no more'); bluetoothAdapter2.info('kk3', { k2: 1 }); console.log('end1');