日志管理
19.1 日志文件接口
/v1/api/logs 与 /v1/api/ops/logs 注册同一组路径。以下用 logs 表示,替换前缀可使用 ops/logs。
GET /v1/api/logs/source
无参数。返回日志源:
{"items":[{"id":"edge-core","label":"Orsus","path":"/var/log/edge-core","subfix":[".log"]}]}
id、label、path 为 string;subfix 是 string[],沿用实现中的拼写。
GET /v1/api/logs/list
别名 GET /v1/api/logs/。
| query | 类型 | 说明 |
|---|---|---|
module | string | 使用 source 返回的 id;虽未标强制绑定,当前实现没有可靠默认日志源,应显式提供合法值 |
range | string | 省略表示不过滤;只支持 1d、7d |
{"items":[{"filename":"edge-core.log","full_path":"/var/log/edge-core/edge-core.log","size":1024,"created":"2026-11-13T08:00:00Z","last_modified":"2026-11-13T08:01:00Z"}],"source":{"id":"edge-core","label":"Orsus","path":"/var/log/edge-core","subfix":[".log"]}}
size 为字节,时间为字符串。未知 module 可能导致 500/1003,而不是自动回退主日志。range 非法为 400/1001。
GET /v1/api/logs/file
query full_path:string,使用列表中的值,URL 编码后发送。响应 data={"filename":"完整路径","content":"日志内容"}。不是旧版的 /logs/{filename}。
curl -sS -G -H "Authorization: Bearer $ORSUS_TOKEN" \
--data-urlencode 'full_path=/var/log/edge-core/edge-core.log' \
"$ORSUS_ORIGIN/v1/api/logs/file"
DELETE /v1/api/logs/
query full_path 同上,无请求体,成功 data={"deleted":"完整路径"}。注意路径末尾的 /。请求应使用列表实际返回的 full_path,不用显示名称拼文件路径。
POST /v1/api/logs/actions/cleanup
别名 POST /v1/api/logs/cleanup。JSON 可省略:
{"max_age_days":7}
max_age_days 为 integer;<=0 使用配置,配置也<=0 则 7 天。按日志源清理过期文件和过期子目录,成功响应:
{"removed":1,"removed_files":[{"full_path":"/var/log/edge-core/old.log","file_name":"old.log","mod_time":"2026-11-01T08:00:00Z"}],"max_age_days":7}
这是实际删除操作,无回收站 API。缺失文件通常 404/1002,其他文件系统错误可为 500/1003;不要依赖旧文档描述的文件名白名单校验行为。
19.2 GET /v1/api/logshipper/services
无参数,返回采集器发现的服务:
{"services":[{"Service":"edge-core","LogDir":"/var/log/edge-core","Parser":"auto"}]}
字段为大写 Service/LogDir/Parser。采集器未配置时也可返回空数组,不代表系统没有日志文件。
19.3 GET /v1/api/logshipper/aggregate
| query | 类型 / 默认 | 说明 |
|---|---|---|
service | string,可选 | 服务名 |
level | string,可选 | 如 ERROR、WARN |
since | string,可选 | 时间范围,如 1h、24h、7d |
limit | integer,100 | 1–1000,非法为 400/1001 |
{"events":[{"ID":1001,"Service":"edge-core","Level":"ERROR","Context":"navigation","TS":"2026-11-13T08:00:00Z","Msg":"downstream timeout","Raw":"example original log line"}],"count":1}
ID 为整数,其余为字符串;TS 为时间。采集器未配置时返回 events=[]、count=0。数据库查询失败为 500/1003。不要把日志时间过滤当成任务游标或可保证不丢失的事件订阅。