1
1
# pylint: disable=missing-docstring
2
2
3
+ import logging
3
4
import os
4
5
import subprocess
5
6
import socket
6
7
7
- import requests
8
8
import structlog
9
9
10
10
from celery .schedules import crontab
27
27
28
28
29
29
_ = gettext = lambda s : s
30
- log = structlog .get_logger (__name__ )
31
-
32
- def send_to_newrelic (logger , log_method , event_dict ):
33
-
34
- if 'request' in event_dict :
35
- # WSGIRequest is not JSONSerializable
36
- event_dict .pop ('request' )
37
-
38
- # Uses the New Relic Log API
39
- # https://docs.newrelic.com/docs/logs/log-management/log-api/introduction-log-api/
40
- headers = {"Api-Key" : '' }
41
-
42
- # Our log message and all the event context is sent as a JSON string
43
- # in the POST body
44
- # https://docs.newrelic.com/docs/logs/log-management/log-api/introduction-log-api/#json-content
45
- payload = {
46
- "message" : f"{ log_method } - { event_dict ['event' ]} " ,
47
- }
48
- payload .update (event_dict )
49
- requests .post ("https://log-api.newrelic.com/log/v1" , json = payload , headers = headers )
50
- return event_dict
30
+ log = logging .getLogger (__name__ )
51
31
52
32
53
33
class CommunityBaseSettings (Settings ):
@@ -271,7 +251,7 @@ def USE_PROMOS(self): # noqa
271
251
'readthedocs.core.middleware.ReferrerPolicyMiddleware' ,
272
252
'django_permissions_policy.PermissionsPolicyMiddleware' ,
273
253
'simple_history.middleware.HistoryRequestMiddleware' ,
274
- 'django_structlog.middlewares.RequestMiddleware ' ,
254
+ 'readthedocs.core.logs.ReadTheDocsRequestMiddleware ' ,
275
255
)
276
256
277
257
AUTHENTICATION_BACKENDS = (
@@ -816,6 +796,11 @@ def DOCKER_LIMITS(self):
816
796
'version' : 1 ,
817
797
'disable_existing_loggers' : True ,
818
798
'formatters' : {
799
+ 'default' : {
800
+ 'format' : LOG_FORMAT ,
801
+ 'datefmt' : '%d/%b/%Y %H:%M:%S' ,
802
+ },
803
+ # structlog
819
804
"plain_console" : {
820
805
"()" : structlog .stdlib .ProcessorFormatter ,
821
806
"processor" : structlog .dev .ConsoleRenderer (),
@@ -829,7 +814,7 @@ def DOCKER_LIMITS(self):
829
814
'console' : {
830
815
'level' : 'INFO' ,
831
816
'class' : 'logging.StreamHandler' ,
832
- 'formatter' : 'plain_console ' ,
817
+ 'formatter' : 'default ' ,
833
818
},
834
819
'debug' : {
835
820
'level' : 'DEBUG' ,
@@ -847,6 +832,12 @@ def DOCKER_LIMITS(self):
847
832
# Always send from the root, handlers can filter levels
848
833
'level' : 'INFO' ,
849
834
},
835
+ 'django_structlog' : {
836
+ 'handlers' : ['null' ],
837
+ 'level' : 'INFO' ,
838
+ # Don't double log at the root logger for these.
839
+ 'propagate' : False ,
840
+ },
850
841
'readthedocs' : {
851
842
'handlers' : ['debug' , 'console' ],
852
843
'level' : 'DEBUG' ,
@@ -859,25 +850,6 @@ def DOCKER_LIMITS(self):
859
850
},
860
851
},
861
852
}
862
- structlog .configure (
863
- processors = [
864
- structlog .stdlib .filter_by_level ,
865
- structlog .processors .TimeStamper (fmt = "iso" ),
866
- structlog .stdlib .add_logger_name ,
867
- structlog .stdlib .add_log_level ,
868
- structlog .stdlib .PositionalArgumentsFormatter (),
869
- structlog .processors .StackInfoRenderer (),
870
- structlog .processors .format_exc_info ,
871
- structlog .processors .UnicodeDecoder (),
872
- send_to_newrelic ,
873
- structlog .stdlib .ProcessorFormatter .wrap_for_formatter ,
874
- ],
875
- context_class = structlog .threadlocal .wrap_dict (dict ),
876
- logger_factory = structlog .stdlib .LoggerFactory (),
877
- wrapper_class = structlog .stdlib .BoundLogger ,
878
- cache_logger_on_first_use = True ,
879
- )
880
-
881
853
882
854
# MailerLite API for newsletter signups
883
855
MAILERLITE_API_SUBSCRIBERS_URL = 'https://api.mailerlite.com/api/v2/subscribers'
0 commit comments