pip -V
pip install git+https://github.com/TencentCloud/tencentcloud-cls-sdk-python.git@v1.0.4
pip show tencentcloud-cls-sdk-python
Name: tencentcloud-cls-sdk-pythonVersion: 1.0.4Summary: TencentCloud cls log service Python client SDKHome-page: https://github.com/TencentCloud/tencentcloud-cls-sdk-pythonAuthor: farmerx
Variables | Type | Required | Description |
endpoint | String | Yes | |
accessKeyId | String | Yes | Cloud API Key Information. For key information acquisition, please visit API Key Management. Please ensure the associated account has the appropriate SDK log upload permission. |
accessKey | String | Yes | TencentCloud API key information. For key information acquisition, please visit API Key Management. Please ensure the associated account has the appropriate SDK log upload permission. |
topic_id | String | Yes | Log topic ID information. |
# Import required librariesimport timefrom tencentcloud.log.logclient import LogClientfrom tencentcloud.log.logexception import LogExceptionfrom tencentcloud.log.cls_pb2 import LogGroupListimport osdef upload(topic_id, client):LogLogGroupList = LogGroupList()LogGroup = LogLogGroupList.logGroupList.add()# Customize the source of the file to be uploaded this time, which will be used as a metadata field in logsLogGroup.filename = "pyXXXX.log"# Customize the address source for this upload, which will be used as a metadata field in logsLogGroup.source = "192.XX.XX.XX"# Custom metadata fieldLogTag = LogGroup.logTags.add()LogTag.key = "key"LogTag.value = "value"Log = LogGroup.logs.add()Log.time = int(round(time.time() * 1000000)) # Get current time as timestamp# Define the content of logsContent = Log.contents.add()Content.key = "Hello"Content.value = "World"try:request = client.put_log_raw(topic_id, LogLogGroupList)print("Request ID:", request.get_request_id())except LogException as e:print("Error uploading log:", e)if name == 'main':# Fill in domain information. Completion guide: https://www.tencentcloud.com/document/product/614/18940?from_cn_redirect=1#.E5.9F.9F.E5.90.8D. See the domain name in the Log upload via API Tab of the link.endpoint = 'https://ap-xxxxxxxx.cls.tencentcs.com';# Fill in cloud API Key Information. For key information acquisition, please visit: https://console.tencentcloud.com/cam/capi# Please ensure the associated account of the key has appropriate log upload permissions. Permission configuration guide: https://www.tencentcloud.com/document/product/614/68374?from_cn_redirect=1#.E4.BD.BF.E7.94.A8-api-.E4.B8.8A.E4.BC.A0.E6.95.B0.E6.8D.AE# This example retrieves from environmental variable. Environment variable configuration guide: https://www.tencentcloud.com/document/product/614/113851?from_cn_redirect=1accessKeyId = os.environ["TENCENTCLOUD_SECRET_ID"]accessKey = os.environ["TENCENTCLOUD_SECRET_KEY"]# Fill in the topic IDtopic_id = '59XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'# Build a log clientclient = LogClient(endpoint, accessKeyId, accessKey)# Call the upload functionupload(topic_id, client)
Feedback