1
1
DRF API Logger
2
- ==============
2
+ ##############
3
3
4
4
|version | |Downloads | |image1 | |Open Source | |Donate |
5
5
@@ -32,7 +32,7 @@ signals for different use cases, or you can do both.
32
32
response time.
33
33
34
34
Installation
35
- ------------
35
+ ************
36
36
37
37
Install or add drf-api-logger.
38
38
@@ -71,13 +71,12 @@ Add in MIDDLEWARE
71
71
' drf_api_logger.middleware.api_logger_middleware.APILoggerMiddleware' , # Add here
72
72
]
73
73
74
- \* Add these lines in the Django Rest Framework settings file.
75
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
74
+
76
75
77
76
Store logs into the database
78
- ----------------------------
77
+ ****************************
79
78
80
- Log every request into the database.
79
+ Log every request into the database. Add these lines in the Django Rest Framework settings file.
81
80
82
81
.. code :: python
83
82
@@ -112,7 +111,7 @@ Note: Make sure to migrate. It will create a table for the logger if
112
111
the table.
113
112
114
113
To listen for the logger signals.
115
- ---------------------------------
114
+ *********************************
116
115
117
116
Listen to the signal as soon as any API is called. So you can log the
118
117
API data into a file or for different use cases.
@@ -154,7 +153,7 @@ Example code to listen to the API Logger Signal.
154
153
API_LOGGER_SIGNAL .listen -= listener_one
155
154
156
155
Queue
157
- ~~~~~
156
+ =====
158
157
159
158
DRF API Logger usage queue to hold the logs before inserting them into
160
159
the database. Once the queue is full, it bulk inserts into the database.
@@ -166,7 +165,7 @@ Specify the queue size.
166
165
DRF_LOGGER_QUEUE_MAX_SIZE = 50 # Default to 50 if not specified.
167
166
168
167
Interval
169
- ~~~~~~~~
168
+ =====
170
169
171
170
DRF API Logger also waits for a period of time. If the queue is not full
172
171
and there are some logs to be inserted, it inserts after the interval
@@ -188,7 +187,7 @@ into the database by specifying the namespace of the app as a list.
188
187
DRF_API_LOGGER_SKIP_NAMESPACE = [' APP_NAMESPACE1' , ' APP_NAMESPACE2' ]
189
188
190
189
Skip URL Name
191
- ~~~~~~~~~~~~~
190
+ =============
192
191
193
192
You can also skip any API to be logged by using the url_name of the API.
194
193
@@ -199,7 +198,7 @@ You can also skip any API to be logged by using the url_name of the API.
199
198
Note: It does not log Django Admin Panel API calls.
200
199
201
200
Hide Sensitive Data From Logs
202
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
201
+ =============================
203
202
204
203
You may wish to hide sensitive information from being exposed in the
205
204
logs. You do this by setting ``DRF_API_LOGGER_EXCLUDE_KEYS `` in
@@ -211,7 +210,7 @@ settings.py to a list of your desired sensitive keys. The default is
211
210
# Sensitive data will be replaced with "***FILTERED***".
212
211
213
212
Change the default database to store API logs
214
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
213
+ =============================================
215
214
216
215
.. code :: python
217
216
@@ -221,7 +220,7 @@ Change the default database to store API logs
221
220
"""
222
221
223
222
Want to identify slow APIs? (Optional)
224
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
223
+ ======================================
225
224
226
225
You can also identify slow APIs by specifying
227
226
``DRF_API_LOGGER_SLOW_API_ABOVE `` in settings.py.
@@ -235,7 +234,7 @@ slow or fast API.
235
234
# Specify in milli-seconds.
236
235
237
236
Want to log only selected request methods? (Optional)
238
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
237
+ =====================================================
239
238
240
239
You can log only selected methods by specifying
241
240
``DRF_API_LOGGER_METHODS `` in settings.py.
@@ -245,7 +244,7 @@ You can log only selected methods by specifying
245
244
DRF_API_LOGGER_METHODS = [' GET' , ' POST' , ' DELETE' , ' PUT' ] # Default to an empty list (Log all the requests).
246
245
247
246
Want to log only selected response status codes? (Optional)
248
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
247
+ ============================================================
249
248
250
249
You can log only selected responses by specifying
251
250
``DRF_API_LOGGER_STATUS_CODES `` in settings.py.
@@ -255,7 +254,7 @@ You can log only selected responses by specifying
255
254
DRF_API_LOGGER_STATUS_CODES = [200 , 400 , 404 , 500 ] # Default to an empty list (Log all responses).
256
255
257
256
Want to see the API information in the local timezone? (Optional)
258
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
257
+ =================================================================
259
258
260
259
You can also change the timezone by specifying
261
260
``DRF_API_LOGGER_TIMEDELTA `` in settings.py. It won’t change the
@@ -272,7 +271,7 @@ Database timezone. It will remain UTC or the timezone you have defined.
272
271
DRF_API_LOGGER_TIMEDELTA = - 30 # Example
273
272
274
273
Ignore data based on maximum request or response body? (Optional)
275
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
274
+ =================================================================
276
275
277
276
Request/Response bodies By default, DRF API LOGGER will save the request
278
277
and response bodies for each request for future viewing no matter how
@@ -289,7 +288,7 @@ This behavior can be configured with the following options additional:
289
288
DRF_API_LOGGER_MAX_RESPONSE_BODY_SIZE = 1024 # default to -1, no limit.
290
289
291
290
API with or without Host
292
- ~~~~~~~~~~~~~~~~~~~~~~~~
291
+ ========================
293
292
294
293
You can specify whether an endpoint of API should have absolute URI or
295
294
not by setting this variable in the DRF settings.py file.
@@ -300,7 +299,7 @@ not by setting this variable in the DRF settings.py file.
300
299
# Possible values are ABSOLUTE, FULL_PATH or RAW_URI
301
300
302
301
Tracing
303
- ~~~~~~~
302
+ =======
304
303
305
304
You can enable tracing by specifying ``DRF_API_LOGGER_ENABLE_TRACING ``
306
305
in settings.py. This will add a tracing ID (UUID.uuid4()) in the signals
@@ -313,7 +312,7 @@ In views, you can use request.tracing_id to get the tracing ID.
313
312
DRF_API_LOGGER_ENABLE_TRACING = True # default to False
314
313
315
314
Want to generate your tracing uuid?
316
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
315
+ ===================================
317
316
318
317
By default, the DRF API Logger uses uuid.uuid4() to generate tracing id.
319
318
If you want to use your custom function to generate uuid, specify
@@ -324,7 +323,7 @@ DRF_API_LOGGER_TRACING_FUNC in the setting.py file.
324
323
DRF_API_LOGGER_TRACING_FUNC = ' foo.bar.func_name'
325
324
326
325
Tracing already present in headers?
327
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
326
+ ===================================
328
327
329
328
If the tracing ID is already coming as a part of request headers, you
330
329
can specify the header name.
@@ -359,7 +358,7 @@ values are: 1. ABSOLUTE (Default) :
359
358
return an insecure URI.
360
359
361
360
Use the DRF API Logger Model to query
362
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
361
+ =====================================
363
362
364
363
You can use the DRF API Logger Model to query some information.
365
364
@@ -403,7 +402,7 @@ DRF API Logger Model:
403
402
verbose_name_plural = ' API Logs'
404
403
405
404
Note:
406
- ~~~~~
405
+ =====
407
406
408
407
After some time, there will be too much data in the database. Searching
409
408
and filtering may get slower. If you want, you can delete or archive the
0 commit comments