LogClient is an SDK client that you can use to access Simple Log Service. It provides various methods for you to create a project, create a Logstore, write logs, and read logs. To use Simple Log Service SDK for Python to initiate a request, you must initialize a LogClient instance and modify the default settings of the LogClient instance based on your business requirements.
Prerequisites
Simple Log Service SDK for Python is installed. For more information, see Install Simple Log Service SDK for Python.
The required access credentials are configured. For more information, see Configure access credentials.
-
Initialize a LogClient instance
API operation
class LogClient(object):
""" Construct the LogClient with endpoint, accessKeyId, accessKey.
:type endpoint: string
:param endpoint: log service host name, for example, ch-hangzhou.log.aliyuncs.com or https://cn-beijing.log.aliyuncs.com
:type accessKeyId: string
:param accessKeyId: aliyun accessKeyId
:type accessKey: string
:param accessKey: aliyun accessKey
"""
__version__ = API_VERSION
Version = __version__
def __init__(self, endpoint, accessKeyId=None, accessKey=None, securityToken=None, source=None,
auth_version=AUTH_VERSION_1, region='', credentials_provider=None):
Request parameters
Parameter | Type | Required | Description | Example |
endpoint | String | Yes | The endpoint. For more information, see Prerequisites. |
|
accessKeyId | String | Yes |
| LTAI**************** |
accessKey | String | Yes |
| yourAccessKeySecret |
securityToken | String | No |
| **************** |
source | String | No | The source. If you do not configure this parameter, the IP address of your server is automatically used. |
|
auth_version | String | No |
|
|
region | String | No | The region of the project. For more information about the supported regions of Simple Log Service, see Supported regions. |
|
Examples
# Import the Simple Log Service SDK for Python package.
from aliyun.log import *
from aliyun.log.auth import AUTH_VERSION_4
# If you obtain an AccessKey pair from environment variables, you must import an operating system (OS) library.
import os
# Obtain an AccessKey ID and an 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', '')
# Specify a Simple Log Service endpoint.
endpoint = "yourEndpoint"
# Create a LogClient instance. In this example, use AUTH_VERSION_4 for signing and the China (Hangzhou) region.
client = LogClient(endpoint, access_key_id, access_key_secret, auth_version=AUTH_VERSION_4, region='cn-hangzhou')
# Import the Simple Log Service SDK for Python package.
from aliyun.log import *
# If you obtain an AccessKey pair from environment variables, you must import an OS library.
import os
# Obtain an AccessKey ID and an 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', '')
# Specify a Simple Log Service endpoint.
endpoint = "yourEndpoint"
# Create a LogClient instance.
client = LogClient(endpoint, access_key_id, access_key_secret)
# Import the Simple Log Service SDK for Python package.
from aliyun.log import *
# If you obtain an AccessKey pair from environment variables, you must import an OS library.
import os
# Obtain an AccessKey ID and an 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', '')
securityToken = os.environ.get('ALIBABA_CLOUD_STS_TOKEN')
# Specify a Simple Log Service endpoint.
endpoint = "yourEndpoint"
# Create a LogClient instance.
client = LogClient(endpoint, access_key_id, access_key_secret, securityToken)
References
After you initialize a LogClient instance, you can call Simple Log Service SDK for Python to create a project and write logs. For more information, see Get started with Simple Log Service SDK for Python.