Create a Logstore
Create a Logstore in a project by calling create_logstore. Configure parameters such as the Logstore name, data retention period, shard count, storage tiers, and Logstore type.
Prerequisites
Before you begin, ensure that you have:
An activated Simple Log Service instance. For more information, see Activate Simple Log Service
An initialized Simple Log Service SDK for Python. For more information, see Initialize Simple Log Service SDK for Python
Usage notes
Three parameters are permanent once set — plan carefully before calling create_logstore:
Logstore name: Must be globally unique within a project. Cannot be changed after creation. Allowed characters: lowercase letters, digits, hyphens (
-), and underscores (_). Must start with a lowercase letter and end with a lowercase letter or digit. Length: 3 to 63 characters.Logstore type: The
modeparameter (standardorquery) cannot be changed after creation.Telemetry type: The
telemetry_typeparameter cannot be changed after creation. When set toMetrics, only a subset of parameters takes effect.
Method signature
def create_logstore(self, project_name, logstore_name,
ttl=30,
shard_count=2,
enable_tracking=False,
append_meta=True,
auto_split=True,
max_split_shard=64,
preserve_storage=False,
encrypt_conf=None,
telemetry_type='',
hot_ttl=-1,
mode=None,
infrequent_access_ttl=-1):
Parameters
|
Parameter |
Type |
Required |
Default |
Description |
|
|
str |
Yes |
- |
The project name. Projects isolate resources and control access. For more information, see Manage a project. |
|
|
str |
Yes |
- |
The Logstore name. Must be globally unique within the project. See Usage notes for naming rules. |
|
|
int |
No |
30 |
The data retention period, in days. Valid values: 1 to 3650. Set to 3650 for permanent storage. This value equals the sum of |
|
|
int |
No |
2 |
The initial number of shards. Valid values: 1 to 10. For more information, see MD5 value range. |
|
|
bool |
No |
False |
Specifies whether to enable web tracking. When set to |
|
|
bool |
No |
True |
Specifies whether to record public IP addresses. When set to |
|
|
bool |
No |
True |
Specifies whether to enable automatic sharding. For more information, see Shard capacity and Automatic sharding. |
|
|
int |
No |
64 |
The maximum number of shards after automatic splitting. Maximum value: 256. Takes effect only when |
|
|
dict |
No |
None |
The encryption configuration. Includes |
|
|
str |
No |
|
The telemetry data type. Valid values: |
|
|
int |
No |
-1 |
The data retention period in the hot storage tier, in days. Minimum value: 7. Cannot exceed |
|
|
str |
No |
None |
The Logstore type. Cannot be changed after creation. Use |
|
|
int |
No |
-1 |
The data retention period in the Infrequent Access (IA) storage tier, in days. Data must remain in IA storage for at least 30 days before it can move to Archive storage. For more information, see Configure intelligent tiered storage. |
Logstore types
|
Type |
Value |
Features |
Cost |
Best for |
|
Standard |
|
Full log analysis, real-time monitoring, interactive analysis |
Standard index traffic fee |
Real-time monitoring, interactive analysis, building observability systems |
|
Query |
|
High-performance queries only. Does not support SQL |
~50% lower index traffic fee |
Large datasets, long retention periods (weeks or months), no analysis required |
For a detailed comparison, see Appendix: logstore comparison by type.
Storage tier movement rules
Data moves between tiers based on the retention periods set for each tier:
|
Movement |
Minimum retention before move |
|
Hot storage to IA storage |
7 days in hot storage |
|
IA storage to Archive storage |
30 days in IA storage |
|
Hot storage to Archive storage |
30 days in hot storage |
Response
For more information, see the CreateLogStore API reference.
Examples
Both examples read credentials from environment variables and call create_logstore with different configuration levels.
Create a Logstore with default settings
Creates a Standard Logstore with the default configuration: 30-day retention, 2 shards, and automatic sharding enabled.
import os
from aliyun.log import LogClient
# Read credentials 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', '')
# Simple Log Service endpoint
endpoint = "cn-hangzhou.log.aliyuncs.com"
# Initialize the client
client = LogClient(endpoint, access_key_id, access_key_secret)
# Project and Logstore names
project_name = "slsproject-1"
logstore_name = "logstore-1"
def main():
res = client.create_logstore(project_name, logstore_name)
res.log_print()
if __name__ == '__main__':
main()
Sample response:
CreateLogStoreResponse:
headers: {'Server': 'AliyunSLS', 'Content-Length': '0', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Thu, 21 Nov 2024 08:20:24 GMT', 'x-log-time': '1732177224', 'x-log-requestid': '673EED4852EDC9797889****'}
Process finished with exit code 0
Create a Logstore with custom configuration
Creates a Standard Logstore with a 90-day retention period, 4 shards, intelligent tiered storage (30 days in hot storage), and automatic sharding enabled up to 128 shards.
import os
from aliyun.log import LogClient
access_key_id = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
access_key_secret = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')
endpoint = "cn-hangzhou.log.aliyuncs.com"
client = LogClient(endpoint, access_key_id, access_key_secret)
project_name = "slsproject-1"
logstore_name = "logstore-2"
def main():
res = client.create_logstore(
project_name,
logstore_name,
ttl=90, # Retain data for 90 days total
shard_count=4, # Start with 4 shards
auto_split=True, # Enable automatic sharding
max_split_shard=128, # Allow up to 128 shards after auto-split
hot_ttl=30, # Keep data in hot storage for 30 days
mode='standard', # Standard Logstore with full analysis
append_meta=True, # Record client IP and receive time
enable_tracking=False # Disable anonymous web tracking
)
res.log_print()
if __name__ == '__main__':
main()
References
-
Logstore management APIs: