All Products
Search
Document Center

Simple Log Service:Contextual query

Last Updated:Jun 03, 2026

View the context of a specific log entry in its original file directly from the SLS console, without logging on to the server.

Prerequisites

How it works

Specify a log source (server and file) and a target log entry. The feature returns surrounding entries from the same file, helping you trace and troubleshoot errors.

Scenarios

For example, a transaction on an O2O food delivery app is logged on a server. A successful transaction spans: logon, browsing, cart addition, order placement, payment, and order generation.

If an order fails, O&M engineers must quickly identify the cause. Traditionally, an administrator must grant them permissions to log on to each server and search application logs by order ID.

With SLS, the engineers can:

  1. Install Logtail on each server, create a machine group and a Logtail configuration in the SLS console, and enable Logtail to upload incremental logs.

  2. On the query and analysis page, specify a time range and locate the failure log by order ID.

  3. Scroll up from the failure log to find related entries, such as a failed credit card deduction.

image

Benefits

  • Identify failure causes without modifying applications or log formats.

  • Query log context directly from the SLS console without server access.

  • Narrow results by time range before performing a contextual query to speed up troubleshooting.

  • Access historical logs anytime in the SLS console, regardless of server storage limits or log rotation.

Procedure

Important

SLS uses a PackId to associate a log with its context. Logtail generates a PackId automatically during collection, and Producer SDKs generate one when writing logs. You can also generate and upload a PackId manually by calling the PutLogs operation. Associate a log with its context using a PackId.

  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. Optional: Enter a search statement and select a time range.

  5. On the Raw Log > Raw Data tab, find the target log and click the Context query icon icon.

    The magnifying glass icon appears to the right of the log entry timestamp.

  6. Scroll up or down on the page to view the context of the specified log.

    • Click Old to load earlier logs.

    • Click Update to load later logs.

    • Click All Fields to manage displayed fields. All fields are visible by default. Click a field name to toggle visibility.

    • In the Filter text box, enter a keyword to filter log entries.

    • In the Highlight text box, enter a string to highlight all occurrences.