Initializing Logs
API Description
You can enable the SDK log function to record log information generated during API calling into log files for subsequent data analysis or fault location. The procedure is as follows:
- Find the log.conf file in the OBS Python SDK.
- Modify parameters in the log.conf file as needed.
- Call ObsClient.initLog to enable the logging function.
- The logging function is disabled by default. You need to enable it manually.
- For details about SDK logs, see Log Analysis.
- You can change the log file permissions in the system based on your actual needs.
The log module of the OBS Python SDK is thread secure but not process secure. If ObsClient is used in multi-process scenarios, you must configure an independent log path for each instance of ObsClient to prevent conflicts when multiple processes write logs concurrently.
Method Definition
obsClient.initLog(
log_config='*** Your Log Configuration Parameters ***',
log_name='*** Your Log Name ***'
)
Constructor Parameter Description
|
Field |
Type |
Optional or Mandatory |
Description |
|---|---|---|---|
|
log_config |
Mandatory |
Log configuration parameter |
|
|
log_name |
str |
Optional |
Log name |
Sample Code
# Import the module.
from obs import ObsClient
# Create an instance of ObsClient.
obsClient = ObsClient(
access_key_id='*** Provide your Access Key ***',
secret_access_key='*** Provide your Secret Key ***',
server='https://your-endpoint'
)
# Import the log module.
from obs import LogConf
# Specify the path to the log configuration file and initialize logs of ObsClient.
obsClient.initLog(LogConf('./log.conf'), '*** Your Log Name ***')
# Use ObsClient to access OBS.
# Disable ObsClient logging.
obsClient.close()
Last Article: Initializing a BucketClient Instance
Next Article: SDK Common Result Objects
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.