Skip to main content

Log Search

Cloud Development log search feature helps you quickly locate and analyze issues during application runtime. It supports multiple search methods, including full-text search, key-value search, and fuzzy matching, enabling you to efficiently find specific log information.

Activate the search feature​

  1. Sign in to the CloudBase platform and select the target environment.
  2. Select Log Monitoring in the left navigation pane and open the Log Management tab at the top of the page.
  3. After the log service is activated, you can start using the search features.

Log Format​

The log printing format automatically includes system default fields, which are as follows:

FieldTypeDefaultDescription
levelstringRequiredLog level (log/info/warn/error)
requestIdstringRequiredRequest ID
modulestringRequiredModule name
resourceNamestringRequiredResource name
errorCodestringRequiredError code
errorMessagestringRequiredError message
requeststringRequiredRequest parameters
responsestringRequiredResponse parameters
msgstringOptionalBrief log content
userstringRequiredUser identifier
srcstringRequiredSource: system/app
startTimestringRequiredRequest start time
timeCoststringRequiredRequest duration
servicestringRequiredService invocation

Cloud Function

FieldTypeDefaultDescription
function_namestringRequiredFunction name
request_idstringRequiredRequest ID
qualifierstringRequiredVersion
Tip
  • If a user custom-prints log object content, custom log fields will be added and a key-value index will be created.
  • If user-defined log fields contain system default fields, the custom log content will take precedence during log search.
  • Restrict user-defined log fields from containing the following keywords: "__FILENAME__", "__TIMESTAMP__", "__LOGSETID__", "__TOPICID__".

Detailed Explanation of Search Methods​

Full-text search is the most commonly used log lookup method. The system automatically splits log content into multiple terms using delimiters, allowing you to input keywords for exact or fuzzy matching.

Usage Scenarios:

  • Search for logs containing specific error messages
  • Search for logs containing a specific function name or variable name
  • Locate operation records containing a specific user ID

Example:

polls # Search for all logs containing "polls"

Full-text Search Example

Key-value search allows you to perform precise lookups based on structured fields in logs. Log content is stored in JSON format, and you can use the key:value format to search for specific field contents.

Common Fields:

FieldDescriptionExample
function_nameCloud function namefunction_name:"user-login"
request_idRequest IDrequest_id:"abc123"
status_codeStatus code; 200 means success and 202 means an intermediate statestatus_code>200 AND status_code!=202
srcLog source: system for system logs, app for user code logssrc:app
logLog contentlog:"Error"
durationExecution duration (ms)duration:>5000
memoryFunction memory configurationmemory:512
user_idUser identifieruser_id:"1307589412"
namespaceEnvironment IDnamespace:"my-env"
qualifierFunction versionqualifier:"$LATEST"
retry_numRetry countretry_num=0

Usage Scenarios:

  • Search for logs that exceed the execution time limit: duration:>5000
  • Search for logs of a specific function: function_name:"user-login"
  • Search for operations of a specific user: user_id:"1307589412"

Example:

action: QueryDocument # Search for all logs where action is 'QueryDocument'

Full-text Search Example

Fuzzy search uses wildcards to match uncertain characters and is suitable for scenarios where partial information is known.

Wildcard Description​

WildcardDescriptionExampleMatching Results
*Matches zero or more arbitrary characters (not supported at the beginning)abc*abc, abcd, abcdef
?Matches any single characterab?cabdc, abec, ab1c
Prefix fuzzy query is not supported

The * wildcard cannot be used at the beginning of a query. Use suffix matching or the complete keyword instead.

Use Cases​

Multi-Version Function Lookup:

action: Query* # Search for all logs where actions start with 'Query'

Fuzzy Search Example 1

Advanced Query Syntax​

Logical Operators​

OperatorSyntaxDescriptionExample
ANDA and B or A BReturns logs containing both A and Berror and timeout
ORA or BReturns logs containing A or Berror or warning
NOTnot BReturns logs that do not contain Bnot debug
MINUSA not BReturns logs that contain A but not Berror not timeout

Special Characters Handling​

SyntaxDescriptionExample
'text'Text within single quotes is treated as literal characters'and' finds logs containing "and"
"text"Text within double quotes is treated as literal characters."error:404" finds logs containing "error:404"
\Escape character that escapes special symbols\: represents the colon character itself

Key-value Pair Query​

key:value # Basic key-value pair query
function_name:"user login" # Values containing spaces need to be enclosed in quotes
"error level":high # Keys containing spaces need to be enclosed in quotes

Composite Query Example​

Troubleshooting​

status_code>200 AND status_code!=202 # Search for failed invocation logs
function_name:"user-login" AND log:"error" # Search for error logs of the user-login function

Performance Analysis​

duration:>5000 # Search for logs with execution time exceeding 5 seconds
src:app AND log:"timeout" # Search for timeout logs in business code

User Behavior Tracking​

user_id:"1307589412" AND log:"login" # Search for login logs of a specific user
request_id:"abc123" # Search for logs of a specific request

Searching Logs with CloudBase CLI​

Besides the console, you can run the same search statements with the CloudBase CLI, which fits batch queries, scripting, and AI-based analysis:

# Search logs; -l controls the number of returned records and --json is easy to consume in scripts
tcb logs search -q 'function_name:"user-login" AND log:"error"' -l 20 --json

# Query CloudRun logs
tcb logs search --service tcbr -q '"error" AND "timeout"' -l 20 --json

For the full CLI parameters, field list, and typical scenarios, see CLI Log Search.

Practical Search Scenarios​

1. Troubleshooting​

# Search for recent failed invocations
status_code>200 AND status_code!=202

# Search for timeout errors of a specific function
function_name:"payment-process" AND log:"timeout"

# Search for exceptions in business code
src:app AND log:"error"

2. Performance Monitoring​

# Search for slow invocations
duration:>3000

# Search for memory exceptions
log:"out of memory"

# Count invocations per function
src:system | select function_name, count(*) as c group by function_name order by c desc limit 20

3. User Behavior Analysis​

# Search for all operations of a specific user
user_id:"1307589412"

# Search for login-related logs
log:"login" OR log:"logout"

# Search for gateway access logs
logType:accesslog