@@ -38,31 +38,66 @@ Before opening a new issue, please search for similar issues. It's possible that
38
38
39
39
## Logging
40
40
41
+ This library uses Python's built-in ` logging ` module to perform logging of error,
42
+ warning, informational and debug messages.
43
+ The components within the SDK Core library use a single logger named ` ibm-cloud-sdk-core ` .
44
+
45
+ For complete information on the logging facility, please see: [ Logging facility for Python] ( https://docs.python.org/3/library/logging.html ) .
46
+
41
47
### Enable logging
42
48
49
+ There are various ways to configure and enable the logging facility.
50
+
51
+ The code example below demonstrates a simple way to enable debug logging by invoking
52
+ the ` logging.basicConfig() ` function.
53
+
54
+ Note that, as a convenience, if you set the logging level to ` DEBUG ` , then HTTP request/response message logging
55
+ is also enabled.
56
+
57
+ The following code example shows how debug logging can be enabled:
43
58
``` python
44
59
import logging
45
- logging.basicConfig(level = logging.DEBUG )
46
- ```
47
60
48
- This would show output of the form:
49
- ```
50
- DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): iam.cloud.ibm.com:443
51
- DEBUG:urllib3.connectionpool:https://iam.cloud.ibm.com:443 "POST /identity/token HTTP/1.1" 200 1809
52
- DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): gateway.watsonplatform.net:443
53
- DEBUG:urllib3.connectionpool:https://gateway.watsonplatform.net:443 "POST /assistant/api/v1/workspaces?version=2018-07-10 HTTP/1.1" 201 None
54
- DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): gateway.watsonplatform.net:443
55
- DEBUG:urllib3.connectionpool:https://gateway.watsonplatform.net:443 "GET /assistant/api/v1/workspaces/883a2a44-eb5f-4b1a-96b0-32a90b475ea8?version=2018-07-10&export=true HTTP/1.1" 200 None
56
- DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): gateway.watsonplatform.net:443
57
- DEBUG:urllib3.connectionpool:https://gateway.watsonplatform.net:443 "DELETE /assistant/api/v1/workspaces/883a2a44-eb5f-4b1a-96b0-32a90b475ea8?version=2018-07-10 HTTP/1.1" 200 28
61
+ # Create a basic logging configuration that:
62
+ # 1. Defines a handler to display messages on the console.
63
+ # 2. Sets the root logger's logging level to DEBUG.
64
+ # 3. Sets the 'format' string used to display messages.
65
+ logging.basicConfig(level = logging.DEBUG , format = ' %(asctime)s [%(name)s :%(levelname)s ] %(message)s ' , force = True )
58
66
```
59
67
60
- ### Low level request and response dump
61
- To get low level information of the requests/ responses:
62
-
63
- ``` python
64
- from http.client import HTTPConnection
65
- HTTPConnection.debuglevel = 1
68
+ When running your application, you should see output like this if debug logging is enabled:
69
+ ```
70
+ 2024-09-16 15:44:45,174 [ibm-cloud-sdk-core:DEBUG] Get authenticator from environment, key=global_search
71
+ 2024-09-16 15:44:45,175 [ibm-cloud-sdk-core:DEBUG] Set service URL: https://api.global-search-tagging.cloud.ibm.com
72
+ 2024-09-16 15:44:45,175 [ibm-cloud-sdk-core:DEBUG] Set User-Agent: ibm-python-sdk-core-3.20.6 os.name=Linux os.version=6.10.9-100.fc39.x86_64 python.version=3.12.5
73
+ 2024-09-16 15:44:45,181 [ibm-cloud-sdk-core:DEBUG] Configuring BaseService instance with service name: global_search
74
+ 2024-09-16 15:44:45,181 [ibm-cloud-sdk-core:DEBUG] Performing synchronous token fetch
75
+ 2024-09-16 15:44:45,182 [ibm-cloud-sdk-core:DEBUG] Invoking IAM get_token operation: https://iam.cloud.ibm.com/identity/token
76
+ 2024-09-16 15:44:45,182 [urllib3.connectionpool:DEBUG] Starting new HTTPS connection (1): iam.cloud.ibm.com:443
77
+ send: b'POST /identity/token HTTP/1.1\r\nHost: iam.cloud.ibm.com\r\nUser-Agent: ibm-python-sdk-core/iam-authenticator-3.20.6 os.name=Linux os.version=6.10.9-100.fc39.x86_64 python.version=3.12.5\r\nAccept-Encoding: gzip, deflate\r\nAccept: application/json\r\nConnection: keep-alive\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 135\r\n\r\n'
78
+ send: b'grant_type=urn%3Aibm%3Aparams%3Aoauth%3Agrant-type%3Aapikey&apikey=[redacted]&response_type=cloud_iam'
79
+ reply: 'HTTP/1.1 200 OK\r\n'
80
+ header: Content-Type: application/json
81
+ header: Content-Language: en-US
82
+ header: Content-Encoding: gzip
83
+ header: Date: Mon, 16 Sep 2024 20:44:45 GMT
84
+ header: Content-Length: 983
85
+ header: Connection: keep-alive
86
+ 2024-09-16 15:44:45,670 [urllib3.connectionpool:DEBUG] https://iam.cloud.ibm.com:443 "POST /identity/token HTTP/11" 200 983
87
+ 2024-09-16 15:44:45,672 [ibm-cloud-sdk-core:DEBUG] Returned from IAM get_token operation
88
+ 2024-09-16 15:44:45,673 [ibm-cloud-sdk-core:DEBUG] Authenticated outbound request (type=iam)
89
+ 2024-09-16 15:44:45,673 [ibm-cloud-sdk-core:DEBUG] Prepared request [POST https://api.global-search-tagging.cloud.ibm.com/v3/resources/search]
90
+ 2024-09-16 15:44:45,673 [ibm-cloud-sdk-core:DEBUG] Sending HTTP request message
91
+ 2024-09-16 15:44:45,674 [urllib3.connectionpool:DEBUG] Starting new HTTPS connection (1): api.global-search-tagging.cloud.ibm.com:443
92
+ send: b'POST /v3/resources/search?limit=1 HTTP/1.1\r\nHost: api.global-search-tagging.cloud.ibm.com\r\nUser-Agent: platform-services-python-sdk/0.57.0 (lang=python; os.name=Linux; os.version=6.10.9-100.fc39.x86_64; python.version=3.12.5)\r\nAccept-Encoding: gzip, deflate\r\nAccept: application/json\r\nConnection: keep-alive\r\ncontent-type: application/json\r\nAuthorization: [redacted]\r\nContent-Length: 39\r\n\r\n'
93
+ send: b'{"query": "GST-sdk-*", "fields": ["*"]}'
94
+ reply: 'HTTP/1.1 200 OK\r\n'
95
+ header: Content-Type: application/json
96
+ header: Content-Length: 22
97
+ header: Date: Mon, 16 Sep 2024 20:44:46 GMT
98
+ header: Connection: keep-alive
99
+ 2024-09-16 15:44:46,079 [urllib3.connectionpool:DEBUG] https://api.global-search-tagging.cloud.ibm.com:443 "POST /v3/resources/search?limit=1 HTTP/11" 200 22
100
+ 2024-09-16 15:44:46,080 [ibm-cloud-sdk-core:DEBUG] Received HTTP response message, status code 200
66
101
```
67
102
68
103
## Open source @ IBM
0 commit comments