Download logs or query and analysis results to your local machine using the SLS console, OpenAPI, Cloud Shell, CLI, or SDK.
Download methods
SLS supports downloading logs or query and analysis results via the console, Cloud Shell, CLI, or SDK.
-
The CLI and SDK methods have no data volume limit for query-based downloads. However, downloads may be interrupted by network instability.
-
Compressed downloads are supported only through the console.
-
If the Logstore uses the pay-by-ingested-data billing method, downloading query and analysis results (SQL results) is free. pay-by-ingested-data.
-
If the Logstore uses the pay-by-feature billing method, downloading query and analysis results (SQL results) requires Dedicated SQL, which incurs fees. Billable items for the pay-by-feature billing method.
|
Comparison item |
Console (recommended) |
OpenAPI |
CLI |
Cloud Shell |
SDK |
|
Data volume limit |
|
|
|
|
|
|
Deployment |
None |
None |
Manually install the SLS CLI. |
Automatic deployment. Wait for initialization on the first run. |
Manually install an SLS SDK and write custom code. |
|
Authorization |
Manual configuration |
Automatic configuration |
Manual configuration |
||
|
Dedicated SQL |
Required for downloading SQL analysis results. |
Required for downloading SQL analysis results. |
Not used |
Not used |
Configure parameters as needed. |
|
Outbound internet traffic |
None |
None |
Fees are waived if the tool is deployed on an ECS instance in the same region as the project and uses an SLS private endpoint. |
Fees are waived if the project is in the China (Shanghai) region. |
Fees are waived if the tool is deployed on an ECS instance in the same region as the project and uses an SLS private endpoint. |
|
Network Attached Storage (NAS) integration |
None |
None |
Manual configuration, if required. |
Automatic configuration |
Manual configuration, if required. |
Alternatively, ship logs to Object Storage Service (OSS) and download them from there. Create an OSS shipping task (New).
Procedure
Console
You can use the SLS console to download logs or query and analysis results to your local machine. The download procedure is similar for both. The following steps use downloading logs as an example. To download query and analysis results, run a query and analysis statement, and then on the Graph tab, click Download Log.
-
If logs exceed the single-task limit, only the maximum allowed number is downloaded. Narrow the time range and download in multiple batches to get all logs.
-
Each Alibaba Cloud account supports up to three concurrent download tasks, with no limit on the total number of downloads. If this limit is exceeded or multiple RAM users initiate downloads simultaneously, wait for running tasks to complete before retrying.
-
Download records are automatically deleted after one day.
-
The system retries a download task automatically if a network error occurs or the query is inaccurate. After three retries, the task status changes to Failed.
-
Log on to the SLS console.
-
In the Projects section, click the target project.
-
In the left-side navigation pane, choose . On the Logstores page, click the target Logstore.
-
Enter a query statement and select a time range.
-
On the Raw Logs tab, choose .
-
In the Download Log dialog box, configure the following parameters and click OK.
Parameter
Description
Task Name
Download task name.
Log Quantity
Number of logs to download.
Data Format
CSV or JSON.
-
CSV: Column names come from the first 100 log fields. New fields in subsequent logs are stored in JSON format in an unnamed final column.
-
JSON: Each log entry is a single JSON line.
Quote
Encloses fields containing special characters to prevent unintended escaping.
Download Inaccurate Results
If you select No, the download fails if the query results are inaccurate.
Compression Method
gzip, lz4, zstd, or none.
Compression significantly reduces file size and download time for large datasets.
-
-
In the Download Tasks dialog box, wait for the Status of the task to change to Successful, and then click Download to save the logs to your local machine.
Alternatively, on the Raw Logs tab, you can choose to open the Download Tasks dialog box and view download records.
OpenAPI
Call the CreateDownloadJob operation to create a log download task.
-
If logs exceed the single-task limit, only the maximum allowed number is downloaded. Narrow the time range and download in multiple batches to get all logs.
-
Each Alibaba Cloud account supports up to three concurrent download tasks, with no limit on the total number of downloads. If this limit is exceeded or multiple RAM users initiate downloads simultaneously, wait for running tasks to complete before retrying.
-
Download records are automatically deleted after one day.
-
The system retries a download task automatically if a network error occurs or the query is inaccurate. After three retries, the task status changes to Failed.
Cloud Shell
Cloud Shell is deployed in China (Shanghai). Downloading from Logstores in other regions incurs outbound internet traffic fees. Pricing. Use Cloud Shell to download log data.
CLI
For large log volumes, use the CLI.
-
Install the CLI. Install the CLI.
-
Obtain your AccessKey pair. AccessKey pair.
-
Run the download command. get_log_all.
Example: The following command downloads logs and saves them to
downloaded_data.txtin the working directory.aliyunlog log get_log_all --project="aliyun-test-project" --logstore="aliyun-test-logstore" --from_time="2024-07-01 15:33:00+8:00" --to_time="2024-07-09 15:23:00+8:00" --query="status:200|select request_method as method,COUNT(*) as pv group by method order by pv" --region-endpoint="cn-hangzhou.log.aliyuncs.com" --format-output=json --access-id="LT***CyGg" --access-key="8P***zi" >> ./downloaded_data.txt
SDK
For large log volumes, use an SDK.
The SDK uses the same API for both downloading and querying logs.
The following code is a Python SDK example:
import os
import time
from aliyun.log import LogClient
from aliyun.log import GetLogsRequest
# The endpoint of Simple Log Service.
endpoint = 'cn-qingdao.log.aliyuncs.com'
# This example shows how to obtain the AccessKey ID and AccessKey secret from environment variables.
accessKeyId = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
accessKey = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')
# The name of the project.
project = 'your-project-name'
# The name of the Logstore.
logstore = 'your-logstore-name'
client = LogClient(endpoint, accessKeyId, accessKey)
# Make sure to replace the project name and Logstore name in the GetLogsRequest call with your actual values.
request = GetLogsRequest(project, logstore, fromTime=int(time()-3600), toTime=int(time()), topic='', query="*", line=100, offset=0, reverse=False)
# Or
# request = GetLogsRequest(project, logstore, fromTime="2018-1-1 10:10:10", toTime="2018-1-1 10:20:10", topic='', query="*", line=100, offset=0, reverse=False)
res = client.get_logs(request)
res.log_print()
> Download Log