SYS_Log.sort() method
筛选并获取日志条目
签名
typescript
function sort(types?: ESYS_LogType | Array<ESYS_LogType>): Promise<Array<ISYS_LogLine>>;1
参数名
参数 | 类型 | 描述 |
|---|---|---|
types | ESYS_LogType | Array<ESYS_LogType> | (可选) 日志类型数组,可以同时指定多种日志类型,如若不指定则为全部类型 |
返回值
Promise<Array<ISYS_LogLine>>
符合筛选条件的日志条目数组
备注
如果日志面板处于打开状态,筛选操作会同时在前端展现
示例
javascript
// 1. 写入三种不同类型的示例日志,便于观察筛选效果
eda.sys_Log.add('嘉立创示例_筛选演示:常规信息');
eda.sys_Log.add('嘉立创示例_筛选演示:电压偏高', 'warn');
eda.sys_Log.add('嘉立创示例_筛选演示:铺铜失败', 'error');
// 2. 不传参数,获取全部类型的日志(返回 Promise,需要 await)
const all = await eda.sys_Log.sort();
console.log('全部日志条目数:', all.length);
// 3. 传入类型数组,只筛选警告和错误两类
const problems = await eda.sys_Log.sort(['warn', 'error']);
console.log('警告和错误条目数:', problems.length);
console.log('问题明细:', problems.map(line => `[${line.type}] ${line.message}`).join(';'));1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13