mcloud-logs

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Cloud CLI: Logs Command

Cloud CLI:日志命令

Execute
mcloud logs
to fetch runtime logs for a Cloud environment's backend or storefront.
执行
mcloud logs
命令以获取云环境中后端或店面的运行时日志。

Constraints

约束条件

  • --follow
    and
    --json
    are incompatible. For programmatic log analysis, use bounded time windows with
    --from
    /
    --to
    and
    --json
    .
  • --follow
    streams until interrupted with
    Ctrl+C
    — do not use in scripts or pipelines.
  • Default retrieves the last 500 log lines from the past 15 minutes.
  • --follow
    --json
    参数互斥。如需进行程序化日志分析,请结合
    --from
    /
    --to
    参数指定时间范围并使用
    --json
    格式输出。
  • --follow
    会持续流式传输日志,直到按下
    Ctrl+C
    中断——请勿在脚本或流水线中使用该参数。
  • 默认会获取过去15分钟内的最后500条日志记录。

Command

命令

bash
mcloud logs \
  --organization <org-id> \
  --project <project-id-or-handle> \
  --environment <environment-handle> \
  [options]
bash
mcloud logs \
  --organization <org-id> \
  --project <project-id-or-handle> \
  --environment <environment-handle> \
  [options]

Options

参数选项

OptionDescriptionDefault
-o/--organization <id>
Organization IDActive context
-p/--project <id-or-handle>
Project ID or handleActive context
-e/--environment <handle>
Environment handleActive context
-f/--follow
Stream logs continuously (incompatible with
--json
)
false
--limit <1-5000>
Max log lines (non-follow mode only)
500
--from <ISO8601>
Start of time range (e.g.
2026-04-22T10:00:00Z
)
15 minutes ago
--to <ISO8601>
End of time range; if >15 min ago, must also pass
--from
now
--search <string>
Filter by substring (same as dashboard search bar)
--deployment <id>
Filter by deployment or build ID
--source <string>
Filter by source (repeatable)
--metadata <key=value>
Filter by metadata field (repeatable; same key merges values)
--type <backend|storefront>
Log stream to query
backend
--json
Output as JSON (incompatible with
--follow
)
false
参数选项说明默认值
-o/--organization <id>
组织ID当前上下文
-p/--project <id-or-handle>
项目ID或标识当前上下文
-e/--environment <handle>
环境标识当前上下文
-f/--follow
持续流式传输日志(与
--json
互斥)
false
--limit <1-5000>
最大日志行数(仅非跟随模式可用)
500
--from <ISO8601>
时间范围起始点(例如
2026-04-22T10:00:00Z
15分钟前
--to <ISO8601>
时间范围结束点;若结束点早于15分钟前,必须同时指定
--from
当前时间
--search <string>
按子字符串过滤(与控制台搜索栏功能一致)
--deployment <id>
按部署或构建ID过滤
--source <string>
按来源过滤(可重复指定)
--metadata <key=value>
按元数据字段过滤(可重复指定;相同键会合并值)
--type <backend|storefront>
要查询的日志流类型
backend
--json
以JSON格式输出(与
--follow
互斥)
false

Examples

示例

bash
undefined
bash
undefined

Basic log fetch (last 500 lines, last 15 min)

基础日志获取(最近15分钟的最后500条记录)

mcloud logs --json
mcloud logs --json

Search for errors

搜索错误日志

mcloud logs --search error --limit 1000 --json
mcloud logs --search error --limit 1000 --json

Filter for HTTP 500 errors via metadata

通过元数据过滤HTTP 500错误日志

mcloud logs --metadata status=500 --limit 1000 --json
mcloud logs --metadata status=500 --limit 1000 --json

Logs for a specific deployment (build or deployment ID)

获取特定部署的日志(构建或部署ID)

mcloud logs --deployment bld_01ABC123 --json
mcloud logs --deployment bld_01ABC123 --json

Structured output for agent analysis

结构化输出用于Agent分析

mcloud logs --search error --json | jq '.[] | {timestamp, source, message}'
mcloud logs --search error --json | jq '.[] | {timestamp, source, message}'

Storefront logs

店面日志

mcloud logs --type storefront --json
mcloud logs --type storefront --json

Stream live logs (human-readable, not for scripts)

流式传输实时日志(适合人类阅读,不用于脚本)

mcloud logs --follow
mcloud logs --follow

Logs within a specific time range

获取特定时间范围内的日志

mcloud logs --from 2026-04-22T10:00:00Z --to 2026-04-22T11:00:00Z --limit 1000 --json
mcloud logs --from 2026-04-22T10:00:00Z --to 2026-04-22T11:00:00Z --limit 1000 --json

Logs from a time until now

获取从指定时间到当前的日志

mcloud logs --from 2026-04-22T10:00:00Z --json
mcloud logs --from 2026-04-22T10:00:00Z --json

Multiple source filters

多来源过滤

mcloud logs --source api --source worker --json
mcloud logs --source api --source worker --json

Multiple metadata filters (HTTP 4xx and 5xx)

多元数据过滤(HTTP 4xx和5xx状态码)

mcloud logs --metadata status=400 --metadata status=500 --limit 500 --json
undefined
mcloud logs --metadata status=400 --metadata status=500 --limit 500 --json
undefined

Time Range Notes

时间范围说明

  • Default window is the past 15 minutes.
  • Pass
    --from
    without
    --to
    to fetch from a time until now.
  • Pass
    --to
    without
    --from
    only if
    --to
    is within the last 15 minutes; otherwise also pass
    --from
    .
  • Both
    --from
    and
    --to
    accept ISO 8601 timestamps.
  • 默认时间窗口为过去15分钟。
  • 仅指定
    --from
    而不指定
    --to
    ,将获取从指定时间到当前的日志。
  • 仅当
    --to
    在过去15分钟内时,才可单独指定
    --to
    ;否则必须同时指定
    --from
  • --from
    --to
    均支持ISO 8601格式的时间戳。