|
| 1 | +.. _logging-page: |
| 2 | + |
| 3 | +Logging |
| 4 | +------- |
| 5 | + |
| 6 | +By default, :class:`arango.ArangoClient` logs API call history using the |
| 7 | +``arango`` logger at ``logging.DEBUG`` level. |
| 8 | + |
| 9 | +Here is an example showing how the logger can be enabled and customized: |
| 10 | + |
| 11 | +.. code-block:: python |
| 12 | +
|
| 13 | + import logging |
| 14 | +
|
| 15 | + from arango import ArangoClient |
| 16 | +
|
| 17 | + logger = logging.getLogger('arango') |
| 18 | +
|
| 19 | + # Set the logging level |
| 20 | + logger.setLevel(logging.DEBUG) |
| 21 | +
|
| 22 | + # Attach a custom handler |
| 23 | + handler = logging.StreamHandler() |
| 24 | + formatter = logging.Formatter('[%(levelname)s] %(message)s') |
| 25 | + handler.setFormatter(formatter) |
| 26 | + logger.addHandler(handler) |
| 27 | +
|
| 28 | + # Initialize and use the client to see the changes |
| 29 | + client = ArangoClient( |
| 30 | + username='root', |
| 31 | + password='', |
| 32 | + enable_logging=True |
| 33 | + ) |
| 34 | + client.databases() |
| 35 | + client.endpoints() |
| 36 | + client.log_levels() |
| 37 | +
|
| 38 | +
|
| 39 | +The logging output for above would look something like this: |
| 40 | + |
| 41 | +.. code-block:: bash |
| 42 | +
|
| 43 | + [DEBUG] GET http://127.0.0.1:8529/_db/_system/_api/database 200 |
| 44 | + [DEBUG] GET http://127.0.0.1:8529/_db/_system/_api/endpoint 200 |
| 45 | + [DEBUG] GET http://127.0.0.1:8529/_db/_system/_admin/log/level 200 |
| 46 | +
|
| 47 | +
|
| 48 | +In order to see the full request information, turn on logging for the requests_ |
| 49 | +library which **python-arango** uses under the hood: |
| 50 | + |
| 51 | +.. _requests: https://github.com/kennethreitz/requests |
| 52 | + |
| 53 | +.. code-block:: python |
| 54 | +
|
| 55 | + import requests |
| 56 | + import logging |
| 57 | +
|
| 58 | + try: # for Python 3 |
| 59 | + from http.client import HTTPConnection |
| 60 | + except ImportError: |
| 61 | + from httplib import HTTPConnection |
| 62 | + HTTPConnection.debuglevel = 1 |
| 63 | +
|
| 64 | + logging.basicConfig() |
| 65 | + logging.getLogger().setLevel(logging.DEBUG) |
| 66 | + requests_log = logging.getLogger("requests.packages.urllib3") |
| 67 | + requests_log.setLevel(logging.DEBUG) |
| 68 | + requests_log.propagate = True |
0 commit comments