All Products
Search
Document Center

Simple Log Service:Modify a logstore

Last Updated:Feb 28, 2025

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

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:

  • Can contain lowercase letters, digits, hyphens (-), and underscores (_).

  • Must start with a lowercase letter and end with a lowercase letter or a digit.

  • Must be 3 to 63 characters in length.

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:

  • The data retention period for the hot storage tier, which is specified by the hot_ttl parameter

  • The data retention period for the Infrequent Access (IA) storage tier, which is specified by the infrequent_access_ttl parameter

  • The data retention period for the Archive storage tier

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:

  • True: If you set this parameter to True, the write permissions on the logstore are granted to anonymous users from the Internet. However, dirty data may be generated because valid authentication is not performed.

  • False (default).

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:

  • True: If you set this parameter to True, Simple Log Service automatically adds the following information to the Tag field of the collected logs:

    • __client_ip__: the public IP address of the client.

    • __receive_time__: the time at which Simple Log Service receives the log. The value is a UNIX timestamp.

  • False (default).

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: enable, encrypt_type, and user_cmk_info. For more information, see EncryptConf and Data encryption.

telemetry_type

string

No

The type of the observable data. Valid values:

  • None (default): log data.

  • Metrics: metric data. If you set this parameter to Metrics, only the following parameters take effect:

    • logstore_name

    • ttl

    • shard_count

    • auto_split

    • max_split_shard

    • append_meta

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.

  • Data in the hot storage tier must be stored for at least seven days before the data can be moved to the IA storage tier. 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.

  • Data in the hot storage tier must be stored for at least 30 days before the data can be moved to the Archive storage tier.

mode

string

No

The type of the logstore. Simple Log Service provides Standard logstores and Query logstores. Valid values:

  • standard (default): Standard logstore. This type of logstore supports the log analysis feature and is suitable for scenarios such as real-time monitoring and interactive analysis. You can use this type of logstore to build a comprehensive observability system.

  • query: Query logstore. This type of logstore supports high-performance query operations. The index traffic fee of a Query logstore is approximately half that of a Standard logstore. Query logstores do not support SELECT statements. Query logstores are suitable for scenarios in which the amount of data is large, the data retention period is long, or log analysis is not required. Data retention periods of weeks or months are considered long.

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 0

References