Skip to content

Commit 9020a7f

Browse files
authored
Merge pull request #58 from GitGuardian/agateau/log
Log all HTTP requests
2 parents af54d23 + 4b4de94 commit 9020a7f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Changed
2+
3+
- All HTTP requests are now logged using Python logger. The log includes the HTTP method, endpoint, status code and duration.

pygitguardian/client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import logging
12
import os
23
import platform
34
import tarfile
5+
import time
46
import urllib.parse
57
from io import BytesIO
68
from pathlib import Path
@@ -29,6 +31,9 @@
2931
)
3032

3133

34+
logger = logging.getLogger(__name__)
35+
36+
3237
# max files size to create a tar from
3338
MAX_TAR_CONTENT_SIZE = 30 * 1024 * 1024
3439

@@ -193,9 +198,18 @@ def request(
193198
if extra_headers
194199
else self.session.headers
195200
)
201+
start = time.time()
196202
response: Response = self.session.request(
197203
method=method, url=url, timeout=self.timeout, headers=headers, **kwargs
198204
)
205+
duration = time.time() - start
206+
logger.debug(
207+
"method=%s endpoint=%s status_code=%s duration=%f",
208+
method,
209+
endpoint,
210+
response.status_code,
211+
duration,
212+
)
199213

200214
self.app_version = response.headers.get("X-App-Version", self.app_version)
201215
self.secrets_engine_version = response.headers.get(

0 commit comments

Comments
 (0)