Skip to content

Commit d7928e7

Browse files
committed
Add logger parameter and update documentation on customer HTTP clients
1 parent 0a8a814 commit d7928e7

12 files changed

+281
-51
lines changed

arango/async.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, connection, return_result=True):
4141
password=connection.password,
4242
http_client=connection.http_client,
4343
database=connection.database,
44-
enable_logging=connection.has_logging
44+
enable_logging=connection.logging_enabled
4545
)
4646
self._return_result = return_result
4747
self._aql = AQL(self)

arango/batch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, connection, return_result=True, commit_on_error=False):
4343
password=connection.password,
4444
http_client=connection.http_client,
4545
database=connection.database,
46-
enable_logging=connection.has_logging
46+
enable_logging=connection.logging_enabled
4747
)
4848
self._id = uuid4()
4949
self._return_result = return_result

arango/client.py

+24-16
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,32 @@
1515
class ArangoClient(object):
1616
"""ArangoDB client.
1717
18-
:param protocol: the internet transfer protocol (default: ``"http"``)
18+
:param protocol: The internet transfer protocol (default: ``"http"``).
1919
:type protocol: str | unicode
20-
:param host: ArangoDB host (default: ``"localhost"``)
20+
:param host: ArangoDB server host (default: ``"localhost"``).
2121
:type host: str | unicode
22-
:param port: ArangoDB port (default: ``8529``)
22+
:param port: ArangoDB server port (default: ``8529``).
2323
:type port: int or str
24-
:param username: ArangoDB username (default: ``"root"``)
24+
:param username: ArangoDB default username (default: ``"root"``).
2525
:type username: str | unicode
26-
:param password: ArangoDB password (default: ``""``)
27-
:param verify: check the connection during initialization. Root privileges
28-
are required to use this check.
26+
:param password: ArangoDB default password (default: ``""``).
27+
:param verify: Check the connection during initialization. Root privileges
28+
are required to use this flag.
2929
:type verify: bool
30-
:param http_client: the HTTP client object
30+
:param http_client: Custom HTTP client to override the default one with.
31+
Please refer to the API documentation for more details.
3132
:type http_client: arango.http_clients.base.BaseHTTPClient
32-
:param enable_logging: log all API requests
33+
:param enable_logging: Log all API requests as debug messages.
3334
:type enable_logging: bool
34-
:param check_cert: verify SSL certificate when making HTTP requests
35+
:param check_cert: Verify SSL certificate when making HTTP requests. This
36+
flag is ignored if a custom **http_client** is specified.
3537
:type check_cert: bool
36-
:param use_session: use session when making HTTP requests
38+
:param use_session: Use session when making HTTP requests. This flag is
39+
ignored if a custom **http_client** is specified.
3740
:type use_session: bool
41+
:param logger: Custom logger to record the API requests with. The logger's
42+
``debug`` method is called.
43+
:type logger: logging.Logger
3844
"""
3945

4046
def __init__(self,
@@ -47,7 +53,8 @@ def __init__(self,
4753
http_client=None,
4854
enable_logging=True,
4955
check_cert=True,
50-
use_session=True):
56+
use_session=True,
57+
logger=None):
5158

5259
self._protocol = protocol
5360
self._host = host
@@ -58,7 +65,7 @@ def __init__(self,
5865
use_session=use_session,
5966
check_cert=check_cert
6067
) if http_client is None else http_client
61-
self._logging = enable_logging
68+
self._logging_enabled = enable_logging
6269
self._conn = Connection(
6370
protocol=self._protocol,
6471
host=self._host,
@@ -67,7 +74,8 @@ def __init__(self,
6774
username=self._username,
6875
password=self._password,
6976
http_client=self._http_client,
70-
enable_logging=self._logging
77+
enable_logging=self._logging_enabled,
78+
logger=logger
7179
)
7280
self._wal = WriteAheadLog(self._conn)
7381

@@ -156,7 +164,7 @@ def logging_enabled(self):
156164
:returns: whether logging is enabled
157165
:rtype: bool
158166
"""
159-
return self._logging
167+
return self._logging_enabled
160168

161169
@property
162170
def wal(self):
@@ -612,7 +620,7 @@ def database(self, name, username=None, password=None):
612620
username=username or self._username,
613621
password=password or self._password,
614622
http_client=self._http_client,
615-
enable_logging=self._logging
623+
enable_logging=self._logging_enabled
616624
))
617625

618626
def create_database(self, name, users=None, username=None, password=None):

arango/cluster.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self,
4040
password=connection.password,
4141
http_client=connection.http_client,
4242
database=connection.database,
43-
enable_logging=connection.has_logging
43+
enable_logging=connection.logging_enabled
4444
)
4545
self._shard_id = shard_id
4646
self._trans_id = transaction_id

arango/connection.py

+31-18
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from arango.http_clients import DefaultHTTPClient
66
from arango.utils import sanitize
77

8-
logger = logging.getLogger('arango')
9-
108

119
class Connection(object):
1210
"""ArangoDB database connection.
@@ -37,7 +35,8 @@ def __init__(self,
3735
username='root',
3836
password='',
3937
http_client=None,
40-
enable_logging=True):
38+
enable_logging=True,
39+
logger=None):
4140

4241
self._protocol = protocol.strip('/')
4342
self._host = host.strip('/')
@@ -52,8 +51,9 @@ def __init__(self,
5251
self._username = username
5352
self._password = password
5453
self._http = http_client or DefaultHTTPClient()
55-
self._logging = enable_logging
54+
self._enable_logging = enable_logging
5655
self._type = 'standard'
56+
self._logger = logger or logging.getLogger('arango')
5757

5858
def __repr__(self):
5959
return '<ArangoDB connection to database "{}">'.format(self._database)
@@ -122,13 +122,26 @@ def http_client(self):
122122
return self._http
123123

124124
@property
125-
def has_logging(self):
125+
def logging_enabled(self):
126126
"""Return ``True`` if logging is enabled, ``False`` otherwise.
127127
128128
:returns: whether logging is enabled or not
129129
:rtype: bool
130130
"""
131-
return self._logging
131+
return self._enable_logging
132+
133+
@property
134+
def has_logging(self): # pragma: no cover
135+
"""Return ``True`` if logging is enabled, ``False`` otherwise.
136+
137+
:returns: whether logging is enabled or not
138+
:rtype: bool
139+
140+
.. warning::
141+
This property will be deprecated in the future.
142+
Use **logging_enabled** instead.
143+
"""
144+
return self._enable_logging
132145

133146
@property
134147
def type(self):
@@ -182,8 +195,8 @@ def head(self, endpoint, params=None, headers=None, **_):
182195
headers=headers,
183196
auth=(self._username, self._password)
184197
)
185-
if self._logging:
186-
logger.debug('HEAD {} {}'.format(url, res.status_code))
198+
if self._enable_logging:
199+
self._logger.debug('HEAD {} {}'.format(url, res.status_code))
187200
return res
188201

189202
def get(self, endpoint, params=None, headers=None, **_):
@@ -205,8 +218,8 @@ def get(self, endpoint, params=None, headers=None, **_):
205218
headers=headers,
206219
auth=(self._username, self._password)
207220
)
208-
if self._logging:
209-
logger.debug('GET {} {}'.format(url, res.status_code))
221+
if self._enable_logging:
222+
self._logger.debug('GET {} {}'.format(url, res.status_code))
210223
return res
211224

212225
def put(self, endpoint, data=None, params=None, headers=None, **_):
@@ -231,8 +244,8 @@ def put(self, endpoint, data=None, params=None, headers=None, **_):
231244
headers=headers,
232245
auth=(self._username, self._password)
233246
)
234-
if self._logging:
235-
logger.debug('PUT {} {}'.format(url, res.status_code))
247+
if self._enable_logging:
248+
self._logger.debug('PUT {} {}'.format(url, res.status_code))
236249
return res
237250

238251
def post(self, endpoint, data=None, params=None, headers=None, **_):
@@ -257,8 +270,8 @@ def post(self, endpoint, data=None, params=None, headers=None, **_):
257270
headers=headers,
258271
auth=(self._username, self._password)
259272
)
260-
if self._logging:
261-
logger.debug('POST {} {}'.format(url, res.status_code))
273+
if self._enable_logging:
274+
self._logger.debug('POST {} {}'.format(url, res.status_code))
262275
return res
263276

264277
def patch(self, endpoint, data=None, params=None, headers=None, **_):
@@ -283,8 +296,8 @@ def patch(self, endpoint, data=None, params=None, headers=None, **_):
283296
headers=headers,
284297
auth=(self._username, self._password)
285298
)
286-
if self._logging:
287-
logger.debug('PATCH {} {}'.format(url, res.status_code))
299+
if self._enable_logging:
300+
self._logger.debug('PATCH {} {}'.format(url, res.status_code))
288301
return res
289302

290303
def delete(self, endpoint, data=None, params=None, headers=None, **_):
@@ -309,6 +322,6 @@ def delete(self, endpoint, data=None, params=None, headers=None, **_):
309322
headers=headers,
310323
auth=(self._username, self._password)
311324
)
312-
if self._logging:
313-
logger.debug('DELETE {} {}'.format(url, res.status_code))
325+
if self._enable_logging:
326+
self._logger.debug('DELETE {} {}'.format(url, res.status_code))
314327
return res

arango/response.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@
44
class Response(object):
55
"""ArangoDB HTTP response.
66
7-
Methods of :class:`arango.http_clients.base.BaseHTTPClient` must return
8-
an instance of this.
7+
Overridden methods of :class:`arango.http_clients.base.BaseHTTPClient` must
8+
return instances of this.
99
10-
:param method: the HTTP method
10+
:param method: The HTTP method name (e.g. ``"post"``).
1111
:type method: str | unicode
12-
:param url: the request URL
12+
:param url: The request URL
13+
(e.g. ``"http://localhost:8529/_db/_system/_api/database"``)
1314
:type url: str | unicode
14-
:param http_code: the HTTP status code
15+
:param headers: A dict-like mapping object containing the HTTP headers.
16+
Must allow case-insensitive key access.
17+
:type headers: collections.MutableMapping
18+
:param http_code: The HTTP status code.
1519
:type http_code: int
16-
:param http_text: the HTTP status text
20+
:param http_text: The HTTP status text. This is used only for printing
21+
error messages, and has no specification to follow.
1722
:type http_text: str | unicode
18-
:param body: the HTTP response body
23+
:param body: The HTTP response body.
1924
:type body: str | unicode | dict
20-
21-
.. note::
22-
This class is meant to be used internally only.
2325
"""
2426

2527
__slots__ = (

arango/transaction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __init__(self,
4949
password=connection.password,
5050
http_client=connection.http_client,
5151
database=connection.database,
52-
enable_logging=connection.has_logging
52+
enable_logging=connection.logging_enabled
5353
)
5454
self._id = uuid4()
5555
self._actions = ['db = require("internal").db']

arango/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '3.11.0'
1+
VERSION = '3.12.0'

docs/classes.rst

+9
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ AQLQueryCache
4545
.. autoclass:: arango.aql.AQLQueryCache
4646
:members:
4747

48+
.. _BaseHTTPClient:
49+
50+
BaseHTTPClient
51+
==============
52+
53+
.. autoclass:: arango.http_clients.base.BaseHTTPClient
54+
:members:
55+
56+
4857
.. _BatchExecution:
4958

5059
BatchExecution

0 commit comments

Comments
 (0)