77For the full list of settings and their values, see
88https://docs.djangoproject.com/en/2.1/ref/settings/
99"""
10+ import logging .config
1011import os
1112
13+ import structlog
1214from configurations import Configuration , values
1315
16+ LOGGING_CONFIG = None
17+ logging .config .dictConfig (
18+ {
19+ "version" : 1 ,
20+ "disable_existing_loggers" : False ,
21+ "handlers" : {"console" : {"class" : "logging.StreamHandler" }},
22+ "loggers" : {
23+ "" : {"level" : "WARNING" , "handlers" : ["console" ], "formatter" : "default" },
24+ "contratospr" : {
25+ "level" : "INFO" ,
26+ "handlers" : ["console" ],
27+ "propagate" : False ,
28+ },
29+ "requests" : {
30+ "level" : "WARNING" ,
31+ "handlers" : ["console" ],
32+ "propagate" : False ,
33+ },
34+ "urllib3" : {
35+ "level" : "WARNING" ,
36+ "handlers" : ["console" ],
37+ "propagate" : False ,
38+ },
39+ "celery" : {"level" : "INFO" , "handlers" : ["console" ], "propagate" : False },
40+ },
41+ }
42+ )
43+
1444
1545class Common (Configuration ):
1646 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
@@ -174,9 +204,9 @@ class Development(Common):
174204 INTERNAL_IPS = ["127.0.0.1" ]
175205
176206
177- class Staging (Common ):
207+ class Production (Common ):
178208 """
179- The in-staging settings.
209+ The in-production settings.
180210 """
181211
182212 # Security
@@ -190,12 +220,6 @@ class Staging(Common):
190220 SECURE_SSL_REDIRECT = values .BooleanValue (True )
191221 SECURE_PROXY_SSL_HEADER = values .TupleValue (("HTTP_X_FORWARDED_PROTO" , "https" ))
192222
193-
194- class Production (Staging ):
195- """
196- The in-production settings.
197- """
198-
199223 AWS_REGION = values .Value ("us-east-1" , environ_prefix = None )
200224 AWS_ACCESS_KEY_ID = values .SecretValue (environ_prefix = None )
201225 AWS_SECRET_ACCESS_KEY = values .SecretValue (environ_prefix = None )
@@ -212,3 +236,22 @@ def CACHES(self):
212236 "OPTIONS" : {"CLIENT_CLASS" : "django_redis.client.DefaultClient" },
213237 }
214238 }
239+
240+
241+ structlog .configure (
242+ processors = [
243+ structlog .stdlib .filter_by_level ,
244+ structlog .stdlib .add_logger_name ,
245+ structlog .stdlib .add_log_level ,
246+ structlog .stdlib .PositionalArgumentsFormatter (),
247+ structlog .processors .TimeStamper (fmt = "iso" ),
248+ structlog .processors .StackInfoRenderer (),
249+ structlog .processors .format_exc_info ,
250+ structlog .processors .UnicodeDecoder (),
251+ structlog .processors .KeyValueRenderer (),
252+ ],
253+ context_class = structlog .threadlocal .wrap_dict (dict ),
254+ logger_factory = structlog .stdlib .LoggerFactory (),
255+ wrapper_class = structlog .stdlib .BoundLogger ,
256+ cache_logger_on_first_use = True ,
257+ )
0 commit comments