You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+132-1Lines changed: 132 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,20 @@ MIDDLEWARE = [
60
60
]
61
61
```
62
62
63
-
This will start storing the request logs using the default `STORAGE_CLASS`, which in fact just uses Python logger named `requestlogs`. Now you can, for example, redirect these logs to a file with the following `LOGGING` configuration:
63
+
Set `'requestlogs.views.exception_handler'` as rest_framework's exception handler
64
+
(this will make sure requestlog entry has all possible data available about the
- Path to the Python class which will handle storing the log entries. Override this if you only need to reimplement the storage mechanism. This may be the case e.g. when choosing what data to store.
100
115
-**ENTRY_CLASS**
101
116
- Path to the Python class which handles the construction of the complete requestlogs entry. Override this for full customization of the requestlog entry behaviour.
117
+
-**SERIALIZER_CLASS**
118
+
- Path to the serializer class which is used to serialize the requestlog entry before storage. By default this is a subclass of `rest_framework.serializers.Serializer`.
102
119
-**SECRETS**
103
120
- List of keys in request/response data which will be replaced with `'***'` in the stored entry.
104
121
-**ATTRIBUTE_NAME**
105
122
- django-requestlogs internally attaches the entry object to the Django request object, and uses this attribute name. Override if it causes collisions.
123
+
124
+
125
+
# Logging with Request ID
126
+
127
+
django-requestlogs also contains a middleware and logging helpers to associate a
128
+
request-specific identifier (uuid) to logging messages. This aims to help
129
+
distinguishing messages to certain request-response cycle, which can be useful
130
+
in an application that receives a high number of requests.
131
+
132
+
The request id is added to the standard logging messages (Django application logs)
133
+
by specifying a custom formatter and using the provided logging filter.
134
+
The request id can be stored to requestlog entries as well.
135
+
The middleware to enable the request id logging does not require the core requestlogs
136
+
middleware to be installed.
137
+
138
+
Under the hood the request id is implemented with help of `threading.local()`.
139
+
140
+
## Installation
141
+
142
+
The feature is enabled by adding `requestlogs.middleware.RequestLogsMiddleware`
143
+
to the `MIDDLEWARE` setting:
144
+
145
+
```python
146
+
MIDDLEWARE= [
147
+
...
148
+
'requestlogs.middleware.RequestLogsMiddleware',
149
+
'requestlogs.middleware.RequestIdMiddleware',
150
+
]
151
+
```
152
+
153
+
Once installed, the application logs should start showing messages with a format such as
154
+
the following:
155
+
156
+
```
157
+
2019-07-18 11:56:07,261 INFO 954fb004fb404751a2fa33326101442c urls:31 Handling GET request
158
+
2019-07-18 11:56:07,262 DEBUG 954fb004fb404751a2fa33326101442c urls:32 No parameters given
159
+
2019-07-18 11:56:07,262 INFO 954fb004fb404751a2fa33326101442c urls:33 All good
160
+
```
161
+
162
+
To add the request id to requestlog entries as well, you can use the provided serializer
0 commit comments