You can use the UpdateLogStore operation to modify the attributes of a logstore, such as the data retention period and the number of shards.
Prerequisites
Simple Log Service is activated.
The Simple Log Service SDK for Python is initialized. For more information, see Initialize Simple Log Service SDK for Python.
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. The project in Simple Log Service is used to isolate the resources of different users and control access to specific resources. For more information, see Manage a project. |
logstore_name | string | Yes | The name of the logstore. The name must be globally unique. You cannot change the name after you create the project. The name must meet the following requirements:
|
ttl | int | No | The data retention period. Unit: days. Valid values: 1 to 3650. If you set this parameter to 3650, data is permanently stored. If the specified retention period elapses, log data is deleted. The data retention period specified by the ttl parameter is the sum of the following time values:
Important If you change the retention period, Simple Log Service deletes all expired data within 1 hour. The data volume that is displayed for Usage Details on the homepage of the Simple Log Service console is updated the next day. For example, if you change the retention period from five days to one day, Simple Log Service deletes the log data of the previous four days within 1 hour. |
shard_count | int | No | The number of shards. For more information, see MD5 value range. Important You cannot change the number of shards by running the update_logstore command. To change the number of shards, you can call the SplitShard or MergeShard operations. |
enable_tracking | bool | No | Specifies whether to enable the web tracking feature. Valid values:
Note The web tracking feature allows you to collect information about the access to browsers, iOS devices, Android devices, and applications in an efficient manner. For more information, see Use the web tracking feature to collect logs. |
append_meta | bool | No | Specifies whether to record public IP addresses. Valid values:
|
auto_split | bool | No | Specifies whether to enable the automatic sharding feature. Valid values:
|
max_split_shard | int | No | The maximum number of shards. After you enable the automatic sharding feature, the maximum number of new shards that can be generated after a shard is automatically split is 256. Note This parameter is required if auto_split is set to True. |
encrypt_conf | dict | No | The data structure of the encryption configuration. The following parameters are included: |
telemetry_type | string | No | The type of the observable data. Valid values:
Important This parameter cannot be modified after it is created. |
hot_ttl | int | No | The data retention period for the hot storage tier. Unit: days. The minimum value is 7, and the maximum value cannot exceed the ttl parameter. If you set this parameter to -1, all data is stored in the hot storage tier. After the data retention period that is specified for the hot storage tier elapses, the data is moved to the IA storage tier. For more information about the storage tiers and movements of data between storage tiers, see Configure intelligent tiered storage.
|
mode | string | No | The type of the logstore. Simple Log Service provides Standard logstores and Query logstores. Valid values:
For more information, see Appendix: logstore comparison by type. |
infrequent_access_ttl | int | No | The data retention period for the IA storage tier. Unit: days. Data in the IA storage tier must be stored for at least 30 days before the data can be moved to the Archive storage tier. For more information, see Configure intelligent tiered storage. |
Response parameters
For information about the response parameters, see UpdateLogStore.
Sample code
from aliyun.log import LogClient
import os
# In this example, the AccessKey ID and AccessKey secret are obtained 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', '')
# Specify a Simple Log Service endpoint.
endpoint = "ap-southeast-1.log.aliyuncs.com"
# Create an instance of the LogClient class.
client = LogClient(endpoint, access_key_id, access_key_secret)
def update_logstore():
# Update a 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():
# Query a 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('auto_split:', 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
auto_split: 32
ttl: 3650
hot_ttl: 7
infrequent_access_ttl: 30
auto_split: True
append_meta: True
Process finished with exit code 0References
The APIs that you can call to manage a logstore are as follows:
For more sample code, see Alibaba Cloud Simple Log Service SDK for Python on GitHub.