Tous les produits
Search
Centre de documentation

Alibaba Cloud SDK:Utiliser la fonctionnalité de journalisation

Dernière mise à jour :Aug 11, 2026

Spécifiez le format de sortie et le chemin de stockage des journaux dans Alibaba Cloud SDK for Python.

Configurer un logger

import os

from aliyunsdkcore.client import AcsClient

import sys

client = AcsClient(
    os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),  # Obtain the AccessKey ID from an environment variable. We recommend that you use the AccessKey ID of a Resource Access Management (RAM) user.
    os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),  # Obtain the AccessKey secret from an environment variable. We recommend that you use the AccessKey secret of the RAM user.
    '<region_id>"'
)

# Export logs in the console or a terminal.
client.set_stream_logger(
    stream=sys.stderr,  # The output object of logs.
    format_string='%(thread)d %(asctime)s %(name)s %(levelname)s %(message)s'  # The output format of logs.
)

# Export the logs in the default format to a file.
client.set_file_logger(
    path='<file_path>'  # The path of the log file.
)