Update a logstore

Updated at:

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:

  • It can contain only lowercase letters, digits, hyphens (-), and underscores (_).

  • It must start with a lowercase letter and end with a lowercase letter or a digit.

  • It must be 3 to 63 characters in length.

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:

  • Retention period for hot storage (hot_ttl)

  • Retention period for infrequent access storage (infrequent_access_ttl)

  • Retention period for archive storage

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.

  • True: Enables web tracking, which grants anonymous write access to the logstore over the internet. Unauthenticated writes may introduce invalid data.

  • False (default): Disables 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.

  • True: Simple Log Service automatically appends the following tag fields to each log entry:

    • __client_ip__: The public IP address of the client.

    • __receive_time__: The UNIX timestamp when Simple Log Service received the log entry.

  • False (default): Disables this feature.

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

telemetry_type

String

No

The type of observability data. Valid values:

  • None: log data. This is the default value.

  • Metrics: The logstore is used for metrics. 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

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 -1 keeps all data in hot storage for the entire ttl period.

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.

  • Data must be kept in hot storage for at least 7 days before moving to infrequent access storage. Data must then remain in infrequent access storage for at least 30 days before moving to archive storage.

  • To move data directly from hot storage to archive storage, it must be kept in hot storage for at least 30 days.

mode

String

No

Simple Log Service provides two types of logstores: Standard and Query.

  • standard (default): Supports end-to-end data analysis in Simple Log Service, suitable for real-time monitoring, interactive analysis, and building observability systems.

  • query: Supports high-performance queries at roughly half the index traffic cost of a Standard logstore, but does not support SQL SELECT statements. Ideal for large data volumes, long retention periods, or scenarios without log analysis requirements.

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