Browse Source

Socket logging for debug mode implemented

master
Dirk Alders 2 months ago
parent
commit
0de3193a0a
1 changed files with 20 additions and 3 deletions
  1. 20
    3
      piki/settings.py

+ 20
- 3
piki/settings.py View File

13
 from pathlib import Path
13
 from pathlib import Path
14
 
14
 
15
 import config
15
 import config
16
+from logging.handlers import SocketHandler as _SocketHandler
16
 import os
17
 import os
17
 import random
18
 import random
18
 import stat
19
 import stat
182
 # Logging Configuration
183
 # Logging Configuration
183
 #
184
 #
184
 ROOT_LOGGER_NAME = 'apps'
185
 ROOT_LOGGER_NAME = 'apps'
186
+default_handler = ['socket'] if DEBUG else ['console']
187
+
188
+
189
+class DjangoSocketHandler(_SocketHandler):
190
+    def emit(self, record):
191
+        if hasattr(record, 'request'):
192
+            record.request = None
193
+        return super().emit(record)
194
+
195
+
185
 LOGGING = {
196
 LOGGING = {
186
     'version': 1,
197
     'version': 1,
187
     'disable_existing_loggers': False,
198
     'disable_existing_loggers': False,
188
     'formatters': {
199
     'formatters': {
189
         'short': {
200
         'short': {
190
-            'format': "%(name)25s - %(levelname)10s - %(message)s",
201
+            'format': "%(asctime)s \"%(name)s - %(levelname)s - %(message)s\"",
191
             'datefmt': '[%d/%b/%Y %H:%M:%S]',
202
             'datefmt': '[%d/%b/%Y %H:%M:%S]',
192
         },
203
         },
193
         'long': {
204
         'long': {
203
             'class': 'logging.StreamHandler',
214
             'class': 'logging.StreamHandler',
204
             'formatter': 'short',
215
             'formatter': 'short',
205
         },
216
         },
217
+        'socket': {
218
+            'level': 'DEBUG',
219
+            'class': 'piki.settings.DjangoSocketHandler',
220
+            'host': '127.0.0.1',
221
+            'port': 19996,
222
+        },
206
     },
223
     },
207
     'loggers': {
224
     'loggers': {
208
         'django': {
225
         'django': {
209
-            'handlers': ['console'],
226
+            'handlers': default_handler,
210
             'level': 'INFO',
227
             'level': 'INFO',
211
             'propagate': False,
228
             'propagate': False,
212
         },
229
         },
213
         ROOT_LOGGER_NAME: {
230
         ROOT_LOGGER_NAME: {
214
-            'handlers': ['console'],
231
+            'handlers': default_handler,
215
             'level': 'DEBUG' if DEBUG else 'INFO',
232
             'level': 'DEBUG' if DEBUG else 'INFO',
216
             'propagate': False,
233
             'propagate': False,
217
         },
234
         },

Loading…
Cancel
Save