|
1 | 1 | # DRF API Logger |
2 | | - |
| 2 | + |
3 | 3 | [](http://pepy.tech/project/drf-api-logger) |
4 | 4 | [](https://pepy.tech/project/drf-api-logger) |
5 | 5 | [](https://opensource.org/) |
@@ -156,9 +156,20 @@ DRF_API_LOGGER_SKIP_URL_NAME = ['url_name1', 'url_name2'] |
156 | 156 | Note: It does not log Django Admin Panel API calls. |
157 | 157 |
|
158 | 158 | ### Hide Sensitive Data From Logs |
159 | | -You may wish to hide sensitive information from being exposed in the logs. You do this by setting `DRF_API_LOGGER_EXCLUDE_KEYS` in settings.py to a list of your desired sensitive keys. The default is |
| 159 | +You may wish to hide sensitive information from being exposed in the logs. |
| 160 | +You do this by setting `DRF_API_LOGGER_EXCLUDE_KEYS` in settings.py to a list of your desired sensitive keys. |
| 161 | +The default is |
160 | 162 | ```python |
161 | 163 | DRF_API_LOGGER_EXCLUDE_KEYS = ['password', 'token', 'access', 'refresh'] |
| 164 | +# Sensitive data will be replaced with "***FILTERED***". |
| 165 | +``` |
| 166 | + |
| 167 | +### Change default database to store API logs |
| 168 | +```python |
| 169 | +DRF_API_LOGGER_DEFAULT_DATABASE = 'default' # Default to "default" if not specified |
| 170 | +""" |
| 171 | +Make sure to migrate the database specified in DRF_API_LOGGER_DEFAULT_DATABASE. |
| 172 | +""" |
162 | 173 | ``` |
163 | 174 |
|
164 | 175 | ### API with or without Host |
@@ -218,5 +229,18 @@ class APILogsModel(Model): |
218 | 229 | execution_time = models.DecimalField(decimal_places=5, max_digits=8, |
219 | 230 | help_text='Server execution time (Not complete response time.)') |
220 | 231 | added_on = models.DateTimeField() |
| 232 | + |
| 233 | + def __str__(self): |
| 234 | + return self.api |
| 235 | +
|
| 236 | + class Meta: |
| 237 | + db_table = 'drf_api_logs' |
| 238 | + verbose_name = 'API Log' |
| 239 | + verbose_name_plural = 'API Logs' |
221 | 240 |
|
222 | 241 | ``` |
| 242 | + |
| 243 | +### Note: |
| 244 | +After sometime, there will be too many data in the database. Searching and filter may get slower. |
| 245 | +If you want, you can delete or archive the older data. |
| 246 | +To improve the searching or filtering, try to add indexes in the 'drf_api_logs' table. |
0 commit comments