11# DRF API Logger
2- ![ version] ( https://img.shields.io/badge/version-1.0.2 -blue.svg )
2+ ![ version] ( https://img.shields.io/badge/version-1.0.3 -blue.svg )
33[ ![ Downloads] ( https://pepy.tech/badge/drf-api-logger )] ( http://pepy.tech/project/drf-api-logger )
44[ ![ Downloads] ( https://pepy.tech/badge/drf-api-logger/month )] ( https://pepy.tech/project/drf-api-logger )
55[ ![ Open Source] ( https://badges.frapsoft.com/os/v1/open-source.svg?v=103 )] ( https://opensource.org/ )
@@ -23,9 +23,9 @@ It logs all the API information for content type "application/json".
23239 . Client IP Address
2424
2525
26- You can log API information into the database or listen to the logger signals for different use-cases or you can do both.
26+ You can log API information into the database or listen to the logger signals for different use-cases, or you can do both.
2727
28- * The logger usage a separate thread to run so it won't affect your API response time.
28+ * The logger usage a separate thread to run, so it won't affect your API response time.
2929
3030## Installation
3131
@@ -154,7 +154,7 @@ DRF_API_LOGGER_SKIP_URL_NAME = ['url_name1', 'url_name2']
154154Note: It does not log Django Admin Panel API calls.
155155
156156### API with or without Host
157- You can specify endpoint of API should have absolute URI or not by setting this variable in DRF settings.py file.
157+ You can specify an endpoint of API should have absolute URI or not by setting this variable in DRF settings.py file.
158158``` python
159159DRF_API_LOGGER_PATH_TYPE = ' ABSOLUTE' # Default to ABSOLUTE if not specified
160160# Possible values are ABSOLUTE, FULL_PATH or RAW_URI
@@ -179,4 +179,36 @@ DRF_API_LOGGER_PATH_TYPE possible values are:
179179
180180 Output: ``` http://127.0.0.1:8000/api/v1/?page=123 ```
181181
182- Note: Similar to ABSOLUTE but skip allowed hosts protection, so may return insecure URI.
182+ Note: Similar to ABSOLUTE but skip allowed hosts protection, so may return an insecure URI.
183+
184+
185+ ### Use DRF API Logger Model to query
186+ You can use the DRF API Logger Model to query some information.
187+
188+ Note: Make sure to set "DRF_API_LOGGER_DATABASE = True" in settings.py file.
189+ ```
190+ from drf_api_logger.models import APILogsModel
191+
192+ """
193+ Example:
194+ Select records for status_code 200.
195+ """
196+ result_for_200_status_code = APILogsModel.objects.filter(status_code=200)
197+ ```
198+
199+ Model:
200+ ```
201+ class APILogsModel(Model):
202+ id = models.BigAutoField(primary_key=True)
203+ api = models.CharField(max_length=512, help_text='API URL')
204+ headers = models.TextField()
205+ body = models.TextField()
206+ method = models.CharField(max_length=10, db_index=True)
207+ client_ip_address = models.CharField(max_length=50)
208+ response = models.TextField()
209+ status_code = models.PositiveSmallIntegerField(help_text='Response status code', db_index=True)
210+ execution_time = models.DecimalField(decimal_places=5, max_digits=8,
211+ help_text='Server execution time (Not complete response time.)')
212+ added_on = models.DateTimeField()
213+
214+ ```
0 commit comments