Skip to main content

Log Search

v3.0.0+

The tcb logs command has been available since v3.0.0.

CloudBase CLI provides a unified log search entry, supporting SCF, Cloud Run, database, large models, and all types of logs using CLS search syntax queries.

Prerequisites

Using the log feature requires that the log service is enabled for the current environment. If not enabled, the CLI will automatically prompt and guide you to enable it (free, with no additional charges).

Search logs in the current environment.

tcb logs search [options]

Parameters

ParameterAbbreviationDescriptionDefault Value
--env-id <envId>-eEnvironment ID
--query <queryString>-qCLS search statement* (all)
--timeRange <range>-tTime range, relative or absolute1h
--limit <n>-lNumber of entries to return (1–100)20
--sort <order>Sort order: desc / ascdesc
--context <cursor>Pagination cursor to transparently pass the last returned value
--service <svc>Log service: tcb / tcbrtcb
--jsonOutput JSON, suitable for script consumption

Example

# View all logs from the last 1 hour
tcb logs search -e my-env-id

# Filter by Function Name, Last 6 Hours
tcb logs search -q 'function_name:"myFunc"' -t 6h -e my-env-id

# View error logs (status codes not 200/202)
tcb logs search -q 'function_name:"myFunc" | select request_id, max(status_code) as status_code, max(ret_msg) as ret_msg where status_code>200 AND status_code!=202 AND retry_num=0 group by request_id limit 10' -e my-env-id

# Exact search by requestId for a single invocation (asc order restores execution sequence)
tcb logs search -q 'request_id:"abc123"' --sort asc -e my-env-id

# View Cloud Run Logs
tcb logs search --service tcbr -q '"error" AND "timeout"' -e my-env-id

# Specify Absolute Time Range
tcb logs search -t "2026-03-10 14:00:00,2026-03-10 15:00:00" -e my-env-id

# Obtain next page
tcb logs search -q 'function_name:"myFunc"' --context "eyJUb2tlb..." -e my-env-id

# Output JSON, suitable for script or AI consumption
tcb logs search --json -e my-env-id

CLS Search Statement Syntax

SCF Available Log Fields

FieldDescriptionExample
function_nameFunction namefunction_name:"myFunc"
request_idUnique ID for this invocationrequest_id:"abc123"
status_codeStatus code, 200=success, 202=intermediate state (should be filtered)status_code>200 AND status_code!=202
srcLog source: system=system logs, app=user code logssrc:app
loglog bodylog:"Error"
namespaceEnvironment IDnamespace:"my-env"
qualifierFunction versionqualifier:"$LATEST"
retry_numRetry count (filter retries with retry_num=0)retry_num=0

Cloud Run Available Log Fields (--service tcbr)

FieldDescriptionExample
__CONTENT__full-text search of log content"error" AND "timeout"
__TAG__.container_nameservice name + instance, supports regex/servername-[0-9]+/
__TAG__.pod_namePod name__TAG__.pod_name:"xxx"

Platform logs (filtering by module:xxx)

ModuleQuery StatementUse Case
Document Databasemodule:databaseDatabase operation logs, eventType:MongoSlowQuery filters slow queries
SQL databasemodule:rdbeventType:MysqlSlowQuery / MysqlFreeze / MysqlRecover
Data Modelmodule:model
Approval Workflowmodule:workflow
User Authenticationmodule:authLogin and authentication events
Large Language Modelmodule:llm AND logType:llm-tracelogAI invocation tracing
Application Deploymentmodule:appeventType:AppProdPub / AppProdDel
Gateway AccesslogType:accesslogHTTP access logs

SQL Analytical Syntax

CLS supports appending SQL analytical statements via the pipe symbol |:

<search condition> | select <field> [where <condition>] [group by <field>] [limit N]

Example: Counting failure counts per function

src:app | select function_name, count(*) as fail_count where status_code>200 AND status_code!=202 group by function_name order by fail_count desc limit 20

Time range format

FormatExampleDescription
Relative time30m / 6h / 1dLast N minutes/hours/days
Absolute time range"2026-03-10 14:00:00,2026-03-10 15:00:00"Start and end time, separated by commas

Typical Query Scenarios

Scenario 1: Troubleshooting errors in a function today

tcb logs search \
-q 'function_name:"myFunc" AND status_code>200 AND status_code!=202' \
-t 24h \
--sort desc \
-e my-env-id

Scenario 2: Tracing complete logs of a single call

# First, use request_id to query, then sort in asc order to restore the chronological sequence
tcb logs search \
-q 'request_id:"abc-request-id-123"' \
--sort asc \
--limit 100 \
-e my-env-id

Scenario 3: Checking slow database queries

tcb logs search \
-q 'module:database AND eventType:MongoSlowQuery' \
-t 24h \
-e my-env-id

Scenario 4: Check Cloud Run Service Exceptions

tcb logs search \
--service tcbr \
-q '"ERROR" AND __TAG__.container_name:"my-service"' \
-t 6h \
-e my-env-id

Collaborating with AI

The --json output of tcb logs search is processed in a structured format, suitable for direct consumption by large models. Recommended workflow:

# 1. Let the AI first learn the syntax of log commands via tcb docs
tcb docs read "logs"

# 2. Execute the query and output for AI analysis
tcb logs search -q 'function_name:"myFunc"' -t 6h --json -e my-env-id | \
# Pass the results to AI for analysis
Best Practices for AI-Generated Commands

If letting a large model generate tcb commands, it is recommended to first use tcb docs search <keyword> or tcb docs read <module> to let the model obtain the real command signatures, avoiding the model 'guessing' commands based on training data and generating hallucinations.