LogClient est le client du SDK Python SLS permettant de gérer les projets et les Logstores, ainsi que d'écrire et de lire des journaux. Initialisez une instance LogClient pour commencer à envoyer des requêtes et modifiez les configurations par défaut selon vos besoins.
Prérequis
Initialiser un LogClient
API
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):
Paramètres de requête
|
Variable |
Type |
Obligatoire |
Description |
Exemple |
|
endpoint |
String |
Oui |
L'endpoint SLS. Obtenez-en un dans la section Prérequis. |
|
|
accessKeyId |
String |
Oui |
|
LTAI |
|
accessKey |
String |
Oui |
|
yourAccessKeySecret |
|
securityToken |
String |
Non |
|
|
|
source |
String |
Non |
Identifiant de source de journal. Par défaut, l'adresse IP du serveur local est utilisée si vous laissez ce paramètre vide ou ne le spécifiez pas. |
|
|
auth_version |
String |
Non |
|
|
|
region |
String |
Non |
Région du projet. Consultez la rubrique Régions prises en charge. |
|
Exemples
Initialisation à l'aide d'une paire AccessKey (signature V4)
# Import the sls package.
from aliyun.log import *
from aliyun.log.auth import AUTH_VERSION_4
# To obtain the AccessKey pair from environment variables, import the os library.
import os
# Obtain 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 = "yourEndpoint"
# Create a LogClient instance. Use V4 signature and specify the region based on your requirements. This example uses the China (Hangzhou) region.
client = LogClient(endpoint, access_key_id, access_key_secret, auth_version=AUTH_VERSION_4, region='cn-hangzhou')
Initialisation à l'aide d'une paire AccessKey (signature V1)
# Import the sls package.
from aliyun.log import *
# To obtain the AccessKey pair from environment variables, import the os library.
import os
# Obtain 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 = "yourEndpoint"
# Create a LogClient instance.
client = LogClient(endpoint, access_key_id, access_key_secret)
Initialisation avec STS
# Import the sls package.
from aliyun.log import *
# To obtain credentials from environment variables, import the os library.
import os
# Obtain the AccessKey ID, AccessKey secret, and STS token 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')
# The endpoint of Simple Log Service.
endpoint = "yourEndpoint"
# Create a LogClient instance.
client = LogClient(endpoint, access_key_id, access_key_secret, securityToken)
Étapes suivantes
Après avoir initialisé LogClient, utilisez les opérations API pour créer des projets et écrire des journaux. Consultez le Démarrage rapide du SDK Python.