跳到正文

日志

采集结构化日志并对全应用日志做全文检索。

概览

基础路径: https://api.infrai.cc/v1/logs
鉴权头: Authorization: Bearer $INFRAI_API_KEY
bash
# Call any /v1/logs capability over raw HTTP — no SDK to install.
# curl:
curl https://api.infrai.cc/v1/logs/... \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json"

方法

logs.ingest

POST /v1/logs/ingest

批量摄取日志条目

参数

名称类型必填说明
entriesLogEntry[]
必填
日志条目数组
idempotency_keystring可选幂等键,用于避免重复写入

返回

AcceptedResult

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/logs/ingest \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"entries": []}'

logs.search

GET /v1/logs/search

搜索日志

参数

名称类型必填说明
qstring可选搜索关键词
filterRecord<string, unknown>可选过滤条件(观测过滤 DSL)
sincestring可选起始时间
untilstring可选结束时间
cursorstring可选分页游标
limitnumber可选每页返回数量

返回

LogQueryResult

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/logs/search \
  -H "Authorization: Bearer $INFRAI_API_KEY"

全部能力

本模块全部已路由能力——完整的对外 REST 契约。上方方法是带讲解的入门示例,此表是完整参考。

能力端点说明
logs.ingestPOST /v1/logs/ingestIngest a batch of log entries.
logs.searchGET /v1/logs/searchSearch logs by keyword and time range.

完整示例

本模块的生产级端到端范例:先一次性配置,再运行业务流程,尽量覆盖本模块的多数 API。

单文件可运行 Python 程序(仅标准库、无 SDK):拷贝后填入 INFRAI_API_KEY 运行,即可按真实业务流逐步体验本模块核心 API——每一步都真实调用并计费,后续步骤复用前一步返回的真实字段。12 行 helper 就是全部集成代码。

python
#!/usr/bin/env python3
"""Infrai · logs — runnable real-app example (single file, zero deps).

Copy this file, set your key, run it: every step is a REAL call to
api.infrai.cc, billed at the real (tiny) per-call price, printing the
live JSON response. Get a key at https://infrai.cc/login (Google/
GitHub sign-in grants $2 free credit); add funds at
https://infrai.cc/billing. No SDK — the 12-line helper below is the
entire integration."""
import json
import os
from urllib import error, request

KEY = os.environ.get("INFRAI_API_KEY") or "ifr_..."  # <- your key
BASE = "https://api.infrai.cc"


# Same raw HTTPS POST/GET as every per-method example on this page —
# wrapped once for reuse. There is nothing else to it: no SDK.
def infrai(method, path, body=None):
    req = request.Request(
        BASE + path, method=method,
        data=json.dumps(body).encode() if body is not None else None,
        headers={"Authorization": f"Bearer {KEY}",
                 "Content-Type": "application/json"})
    try:
        with request.urlopen(req, timeout=60) as r:
            return json.loads(r.read())
    except error.HTTPError as e:
        return json.loads(e.read())


def show(label, resp):
    print(f"\n== {label} ==")
    print(json.dumps(resp, indent=2, ensure_ascii=False))
    return resp


# 1) logs.ingest — POST /v1/logs/ingest · Ingest a batch of log entries.
r1 = show("logs.ingest", infrai("POST", "/v1/logs/ingest", {"entries":[]}))

# 2) logs.search — GET /v1/logs/search · Search logs by keyword and time range.
r2 = show("logs.search", infrai("GET", "/v1/logs/search"))