Scan logs

Updated at:
Copy as MD

SLS scan queries and analyzes logs by scanning target fields without requiring index configuration. It supports scan query (SPL) and scan analysis (SQL).

Prerequisites

  • Logs are collected. Data collection.

  • Indexes are created. Create an index.

    Important

    The target scan field does not need an index, but query statements still depend on indexes.

Procedure

  1. Log on to the Simple Log Service console.

  2. In the Projects section, click the one you want.

    image

  3. On the Log Storage > Logstores tab, click the logstore you want.

    image

  4. In the search box, enter a scan statement.

    Supported formats: Query statement | SPL statement or Query statement | set session mode=scan; Analytic statement (Standard SQL).

  5. In the upper-right corner, set the time range.

    You can set a relative time, a time frame, or a custom time range. Minimum granularity: one minute.

Automatic scanning

Important

Automatic scanning and page turning are available only for scan queries.

If No results found for this scan appears after a scan query, click the Scan icon. The system automatically scans until it finds matching logs or reaches 20 attempts.

Scan logs

The Automatic Scanning dialog box shows the scan progress.

Automatic scanning

Pagination

When you turn a page, SLS runs another scan to ensure continuous results.

Each scan processes up to 100,000 logs. A page may return fewer results than the Items per Page value, but you can still go to the next page. This means fewer than Items per Page matching logs were found in the current 100,000-log batch.

For example, with 200,000 total logs and Items per Page set to 20, one scan may return only 15 logs while the next page button remains active. This means only 15 of the first 100,000 logs matched. Click next to scan the remaining 100,000 logs.

Pagination

Examples

  • Query logs for successful requests.

    • Scan statement

      * | where Status='Success'
    • Scan resultsScan results

  • Query logs for a specific file at a specific time.

    • Scan statement

      * | where file = 'file:Android' | where time ='[2024-04-24T10:07:27.427014479]'
    • Scan resultsScan results

  • Count requests by status.

    • Scan statement

      Note

      Scan analysis requires set session mode=scan; before the SQL statement.

      * | set session mode=scan; SELECT Status, count(*) AS PV GROUP BY Status
    • Scan resultsScan analysis

API calls

Call the GetLogs operation to use scan programmatically. Query logs in a Logstore.

Important

Add set session mode=scan; to the analytic statement in the query parameter. For example: * | set session mode=scan; select count(*) as pv.