-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #315 from pcattori/log-response-body
Logging improvements
- Loading branch information
Showing
7 changed files
with
131 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Logging | ||
|
||
**IMPORTANT** Make sure to configure logging BEFORE `import`ing from 3rd party | ||
libraries. Logging will use the first configuration it finds, and if a library | ||
configures logging before you, your configuration will be ignored. | ||
|
||
--- | ||
|
||
To configure logging, simply follow the [official Python logging HOWTO](https://docs.python.org/3/howto/logging.html#logging-howto). | ||
|
||
For example: | ||
```python | ||
# script.py | ||
import logging | ||
|
||
logging.basicConfig(filename="script.log", level=logging.INFO) | ||
|
||
# configure logging before other imports | ||
|
||
from tamr_unify_client import Client | ||
from tamr_unify_client.auth import UsernamePasswordAuth | ||
|
||
auth = UsernamePasswordAuth("my username", "my password") | ||
tamr = Client(auth, host="myhost") | ||
|
||
for p in tamr.projects: | ||
print(p) | ||
|
||
for d in tamr.datasets: | ||
print(d) | ||
|
||
# should cause an HTTP error | ||
tamr.get("/invalid/api/path").successful() | ||
``` | ||
|
||
This will log all API requests made and print the response bodies for any | ||
requests with HTTP error codes. | ||
|
||
If you want to **only** configure logging for the Tamr Client: | ||
```python | ||
import logging | ||
logger = logging.getLogger('tamr_unify_client') | ||
logger.setLevel(logging.INFO) | ||
logger.addHandler(logging.FileHandler('tamr-client.log')) | ||
|
||
# configure logging before other imports | ||
|
||
from tamr_unify_client import Client | ||
from tamr_unify_client import UsernamePasswordAuth | ||
|
||
# rest of script goes here | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
import logging | ||
|
||
from tamr_unify_client.client import Client | ||
|
||
# https://docs.python-guide.org/writing/logging/#logging-in-a-library | ||
logging.getLogger(__name__).addHandler(logging.NullHandler()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters