Update a Logtail configuration
Update a Logtail configuration by using the UpdateConfig operation of the Python SDK.
Prerequisites
The following prerequisites are met:
Parameters
def update_logtail_config(self, project_name, config_detail):
Request parameters
|
Parameter |
Type |
Required |
Description |
|
project_name |
String |
Yes |
Project name: A project is a resource management unit in Log Service that provides the primary boundary for multi-user isolation and access control. For more information, see Manage a Project. |
|
config_detail |
LogtailConfig |
Yes |
The Logtail configuration details. Supported methods: This example uses |
SimpleFileConfigDetail parameters
|
Parameter |
Type |
Required |
Description |
|
logstoreName |
String |
Yes |
Logstore name: A Logstore is a unit in Log Service for collecting, storing, and querying logs. For more information, see Manage a Logstore. |
|
configName |
String |
Yes |
The Logtail configuration name. The name must be unique within a project and cannot be modified after creation. For more information, see Logtail (legacy). The name must meet the following requirements:
|
|
logPath |
String |
Yes |
The absolute path of the log file. |
|
filePattern |
String |
Yes |
The name of the log file. You can use the asterisk ( |
|
localStorage |
bool |
No |
Specifies whether to enable local caching.
|
|
enableRawLog |
bool |
No |
Specifies whether to upload raw logs.
|
|
topicFormat |
String |
No |
The method for generating log topics.
For more information, see Log topics. |
|
fileEncoding |
String |
No |
The file encoding format. Valid values: |
|
maxDepth |
int |
No |
The maximum depth of directories to monitor. Valid values: 0 to 1000. A value of 0 indicates that only the current directory is monitored. |
|
preserve |
bool |
No |
Specifies whether to time out a log file that is not updated within a specified period.
|
|
preserveDepth |
String |
No |
If |
|
filterKey |
List |
No |
The field used to filter logs. A log is collected only when this field matches the |
|
filterRegex |
String |
No |
The regular expression that corresponds to |
Response parameters
For more information about the response parameters, see Update a Logtail configuration.
Sample code
from aliyun.log import LogClient
from aliyun.log.logtail_config_detail import SimpleFileConfigDetail
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 for Log Service. Replace it with the endpoint of the region where your Project resides.
endpoint = "cn-hangzhou.log.aliyuncs.com"
client = LogClient(endpoint, access_key_id, access_key_secret)
project = "slsproject-1"
logstore = "logstore-1"
configName = logstore + "-stt1-logtail"
logPath = "/data/logs"
filePattern = "*_json.log"
# Update the configuration for collecting simple text logs.
def main():
try:
config_detail = SimpleFileConfigDetail(logstore, configName, logPath, filePattern)
res = client.update_logtail_config(project, config_detail)
res.log_print()
except Exception as error:
print(error)
if __name__ == '__main__':
main()
Sample response
UpdateLogtailConfigResponse:
headers: {'Server': 'AliyunSLS', 'Content-Length': '0', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Fri, 22 Nov 2024 07:26:50 GMT', 'x-log-time': '1732260410', 'x-log-requestid': '6740323AFB9C5EFB9980****'}
Process finished with exit code 0
Related documents
-
For API operations to manage Logtail configurations, see the following topics:
-
For more sample code, see Aliyun Log Python SDK on GitHub.