Skip to content

Commit 1b4cf80

Browse files
committed
Completed logging documentation
1 parent 9490914 commit 1b4cf80

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

arangoasync/connection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ async def process_request(self, request: Request) -> Response:
177177
host_index = self._host_resolver.get_host_index()
178178
for tries in range(self._host_resolver.max_tries):
179179
try:
180+
logger.debug(
181+
f"Sending request to host {host_index} ({tries}): {request}"
182+
)
180183
resp = await self._http_client.send_request(
181184
self._sessions[host_index], request
182185
)

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Contents
6767
compression
6868
errors
6969
errno
70+
logging
7071

7172
**Development**
7273

docs/logging.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Logging
2+
-------
3+
4+
If if helps to debug your application, you can enable logging to see all the requests sent by the driver to the ArangoDB server.
5+
6+
.. code-block:: python
7+
8+
import logging
9+
from arangoasync import ArangoClient
10+
from arangoasync.auth import Auth
11+
from arangoasync.logger import logger
12+
13+
# Set up logging
14+
logging.basicConfig(level=logging.DEBUG)
15+
logger.setLevel(level=logging.DEBUG)
16+
17+
# Initialize the client for ArangoDB.
18+
async with ArangoClient(hosts="http://localhost:8529") as client:
19+
auth = Auth(username="root", password="passwd")
20+
21+
# Connect to "test" database as root user.
22+
db = await client.db("test", auth=auth)
23+
24+
# Get the API wrapper for "students" collection.
25+
students = db.collection("students")
26+
27+
# Insert a document into the collection.
28+
await students.insert({"name": "John Doe", "age": 25})
29+
30+
The insert generates a log message similar to: `DEBUG:arangoasync:Sending request to host 0 (0): <POST /_db/_system/_api/document/students>`.

0 commit comments

Comments
 (0)