Skip to content

Commit 6606793

Browse files
committed
docs(logging): fix example to include missing StreamHandler
The previous logging example set the log level but did not include a StreamHandler, causing no output in many environments. This fix adds a StreamHandler and formatter to ensure logs are visible in terminal/script use.
1 parent 9fbe4bf commit 6606793

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

docs/logging.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,31 @@ In the following code, the logging level is set to `INFO`, and the Google Transl
1616

1717
```python
1818
import logging
19+
import sys
1920
from googleapiclient.discovery import build
2021

22+
# Configure root logger
2123
logger = logging.getLogger()
2224
logger.setLevel(logging.INFO)
2325

26+
# Ensure logs are printed to stdout
27+
handler = logging.StreamHandler(sys.stdout)
28+
formatter = logging.Formatter('%(levelname)s:%(name)s:%(message)s')
29+
handler.setFormatter(formatter)
30+
logger.addHandler(handler)
31+
2432
def main():
25-
service = build('translate', 'v2', developerKey='your_api_key')
26-
print service.translations().list(
27-
source='en',
28-
target='fr',
29-
q=['flower', 'car']
33+
service = build('translate', 'v2', developerKey='your_api_key')
34+
result = service.translations().list(
35+
source='en',
36+
target='fr',
37+
q=['flower', 'car']
3038
).execute()
39+
print(result)
3140

3241
if __name__ == '__main__':
33-
main()
42+
main()
43+
3444
```
3545

3646
The output of this code should print basic logging info:
@@ -48,4 +58,4 @@ For even more detailed logging you can set the debug level of the [httplib2](htt
4858
```python
4959
import httplib2
5060
httplib2.debuglevel = 4
51-
```
61+
```

0 commit comments

Comments
 (0)