Update a logstore
You can update logstore properties, such as the data retention period and shard count, by calling the UpdateLogStore operation.
Prerequisites
Before you begin, complete the following tasks:
Parameters
def update_logstore(self, project_name, logstore_name, ttl=None, enable_tracking=None, shard_count=None,
append_meta=None,
auto_split=None,
max_split_shard=None,
preserve_storage=None,
encrypt_conf=None,
hot_ttl=-1,
mode=None,
telemetry_type=None,
infrequent_access_ttl=-1
):
Request parameters
|
Parameter |
Type |
Required |
Description |
|
project_name |
String |
Yes |
The name of the Project Name. A Project is a resource management unit in Simple Log Service that isolates resources and controls access for multiple users. For more information, see Manage a Project. |
|
logstore_name |
String |
Yes |
The name of the Logstore Name. The name must be unique within a Project and cannot be changed after creation. The name must meet the following requirements:
|
|
ttl |
int |
No |
The Data Retention Period, in days. Valid values: 1 to 3650. A value of 3650 indicates permanent storage. When the retention period expires, logs are deleted. The data retention period (ttl) is the sum of the following retention periods:
Important
After you change the data retention period, Simple Log Service deletes all expired data within 1 hour, and console usage details are updated the next day. For example, reducing the retention period from 5 days to 1 day causes the system to delete the previous 4 days of log data within 1 hour. |
|
shard_count |
int |
No |
The number of shards. For more information, see Shard range. Important
This operation does not support changing the shard count. To increase or decrease the number of shards, call the split a shard or merge shards operation. |
|
enable_tracking |
bool |
No |
Specifies whether to enable web tracking.
Note
The web tracking feature allows you to collect access information from browsers, iOS/Android apps, and other clients. For more information, see Use web tracking to collect front-end logs. |
|
append_meta |
bool |
No |
Specifies whether to record the Log Public IP.
|
|
auto_split |
bool |
No |
Specifies whether to enable Automatic Sharding.
|
|
max_split_shard |
int |
No |
The Maximum Shards for automatic splitting. After you enable Automatic Sharding, the logstore can automatically split into up to 256 shards. Important
This parameter is required when auto_split is set to True. |
|
encrypt_conf |
dict |
No |
The encryption configuration dictionary, which includes the |
|
telemetry_type |
String |
No |
The type of observability data. Valid values:
Important
You cannot change this parameter after the logstore is created. |
|
hot_ttl |
int |
No |
The retention period for data in hot storage, in days. The value must be at least 7 and no greater than the ttl value. A value of After the hot storage period expires, Simple Log Service moves the data to infrequent access storage. For more information about storage tiers and the data lifecycle, see Manage intelligent tiered storage.
|
|
mode |
String |
No |
Simple Log Service provides two types of logstores: Standard and Query.
For more information, see Comparison of logstore types. |
|
infrequent_access_ttl |
int |
No |
The retention period, in days, for data in the infrequent access storage tier. Data must remain in this tier for at least 30 days before moving to archive storage. For more information, see Manage intelligent tiered storage. |
Response parameters
For information about the response parameters, see UpdateLogStore.
Sample code
from aliyun.log import LogClient
import os
# This example obtains the AccessKey ID and AccessKey secret from environment variables.
access_key_id = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
access_key_secret = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')
# The endpoint of Simple Log Service.
endpoint = "cn-hangzhou.log.aliyuncs.com"
# Instantiate the LogClient class.
client = LogClient(endpoint, access_key_id, access_key_secret)
def update_logstore():
# Update the configuration of the logstore.
ttl = 3650
enable_tracking = True
shard_count = None
append_meta = True
auto_split = True
max_split_shard = 32
preserve_storage = None
encrypt_conf = None
hot_ttl = 7
mode = None
telemetry_type = None
infrequent_access_ttl = 30
res = client.update_logstore(project_name, logstore_name, ttl, enable_tracking, shard_count,
append_meta, auto_split, max_split_shard, preserve_storage, encrypt_conf,
hot_ttl, mode, telemetry_type, infrequent_access_ttl)
res.log_print()
def get_logstore():
# Retrieve information about the specified logstore.
res = client.get_logstore(project_name, logstore_name)
print('GetLogStoreResponse:')
print('logstore_name:', res.logstore_name)
print('shard_count:', str(res.shard_count))
print('auto_split:', res.auto_split)
print('max_split_shard:', str(res.max_split_shard))
print('ttl:', str(res.ttl))
print('hot_ttl:', str(res.hot_ttl))
print('infrequent_access_ttl:', str(res.infrequent_access_ttl))
print('enable_tracking:', res.enable_tracking)
print('append_meta:', res.append_meta)
if __name__ == '__main__':
project_name = 'slsproject-1'
logstore_name = "logstore-1"
update_logstore()
get_logstore()
Sample response
UpdateLogStoreResponse:
headers: {'Server': 'AliyunSLS', 'Content-Length': '0', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Mon, 17 Feb 2025 07:00:01 GMT', 'x-log-time': '1739775601', 'x-log-requestid': '67B2DE711508ADEE94320806'}
GetLogStoreResponse:
logstore_name: logstore-1
shard_count: 2
auto_split: True
max_split_shard: 32
ttl: 3650
hot_ttl: 7
infrequent_access_ttl: 30
enable_tracking: True
append_meta: True
Process finished with exit code 0
References
-
Logstore management API operations:
-
For more code examples, see Aliyun Log Python SDK on GitHub.