|
25 | 25 | import sys |
26 | 26 | import dotenv |
27 | 27 | from socket import gethostname, gethostbyname |
28 | | - |
| 28 | +import google.cloud.logging |
29 | 29 |
|
30 | 30 | SECURE_LOCAL_PATH = os.environ.get('SECURE_LOCAL_PATH', '') |
31 | 31 |
|
|
337 | 337 |
|
338 | 338 | TEST_RUNNER = 'django.test.runner.DiscoverRunner' |
339 | 339 |
|
340 | | -# A sample logging configuration. The only tangible logging |
341 | | -# performed by this configuration is to send an email to |
342 | | -# the site admins on every HTTP 500 error when DEBUG=False. |
343 | | -# See http://docs.djangoproject.com/en/dev/topics/logging for |
344 | | -# more details on how to customize your logging configuration. |
| 340 | +handler_set = ['console_dev', 'console_prod'] |
| 341 | +handlers = { |
| 342 | + 'mail_admins': { |
| 343 | + 'level': 'ERROR', |
| 344 | + 'filters': ['require_debug_false'], |
| 345 | + 'class': 'django.utils.log.AdminEmailHandler' |
| 346 | + }, |
| 347 | + 'console_dev': { |
| 348 | + 'level': 'DEBUG', |
| 349 | + 'filters': ['require_debug_true'], |
| 350 | + 'class': 'logging.StreamHandler', |
| 351 | + 'formatter': 'verbose', |
| 352 | + }, |
| 353 | + 'console_prod': { |
| 354 | + 'level': 'DEBUG', |
| 355 | + 'filters': ['require_debug_false'], |
| 356 | + 'class': 'logging.StreamHandler', |
| 357 | + 'formatter': 'simple', |
| 358 | + }, |
| 359 | +} |
| 360 | + |
| 361 | +if IS_APP_ENGINE: |
| 362 | + # We need to hook up Python logging to Google Cloud Logging for AppEngine (or nothing will be logged) |
| 363 | + client = google.cloud.logging_v2.Client() |
| 364 | + client.setup_logging() |
| 365 | + handler_set.append('stackdriver') |
| 366 | + handlers['stackdriver'] = { |
| 367 | + 'level': 'DEBUG', |
| 368 | + 'filters': ['require_debug_false'], |
| 369 | + 'class': 'google.cloud.logging_v2.handlers.CloudLoggingHandler', |
| 370 | + 'client': client, |
| 371 | + 'formatter': 'verbose' |
| 372 | + } |
| 373 | + |
345 | 374 | LOGGING = { |
346 | 375 | 'version': 1, |
347 | 376 | 'disable_existing_loggers': False, |
|
355 | 384 | }, |
356 | 385 | 'formatters': { |
357 | 386 | 'verbose': { |
358 | | - 'format': '[%(levelname)s] @%(asctime)s in %(module)s/%(process)d/%(thread)d - %(message)s' |
| 387 | + 'format': '[%(name)s] [%(levelname)s] @%(asctime)s in %(module)s/%(process)d/%(thread)d - %(message)s' |
359 | 388 | }, |
360 | 389 | 'simple': { |
361 | | - 'format': '[%(levelname)s] @%(asctime)s in %(module)s: %(message)s' |
| 390 | + 'format': '[%(name)s] [%(levelname)s] @%(asctime)s in %(module)s: %(message)s' |
362 | 391 | }, |
363 | 392 | }, |
364 | | - 'handlers': { |
365 | | - 'mail_admins': { |
366 | | - 'level': 'ERROR', |
367 | | - 'filters': ['require_debug_false'], |
368 | | - 'class': 'django.utils.log.AdminEmailHandler' |
369 | | - }, |
370 | | - 'console_dev': { |
371 | | - 'level': 'DEBUG', |
372 | | - 'filters': ['require_debug_true'], |
373 | | - 'class': 'logging.StreamHandler', |
374 | | - 'formatter': 'verbose', |
375 | | - }, |
376 | | - 'console_prod': { |
377 | | - 'level': 'DEBUG', |
378 | | - 'filters': ['require_debug_false'], |
379 | | - 'class': 'logging.StreamHandler', |
380 | | - 'formatter': 'simple', |
381 | | - }, |
| 393 | + 'handlers': handlers, |
| 394 | + 'root': { |
| 395 | + 'level': 'INFO', |
| 396 | + 'handlers': handler_set |
382 | 397 | }, |
383 | 398 | 'loggers': { |
384 | | - 'django.request': { |
385 | | - 'handlers': ['console_dev', 'console_prod'], |
386 | | - 'level': 'DEBUG', |
387 | | - 'propagate': False, |
388 | | - }, |
389 | | - 'main_logger': { |
390 | | - 'handlers': ['console_dev', 'console_prod'], |
391 | | - 'level': 'DEBUG', |
392 | | - 'propagate': True, |
| 399 | + '': { |
| 400 | + 'level': 'INFO', |
| 401 | + 'handlers': handler_set, |
| 402 | + 'propagate': True |
393 | 403 | }, |
394 | | - 'axes': { |
395 | | - 'handlers': ['console_dev', 'console_prod'], |
396 | | - 'level': 'DEBUG', |
397 | | - 'propagate': True, |
| 404 | + 'django': { |
| 405 | + 'level': 'INFO', |
| 406 | + 'handlers': handler_set, |
| 407 | + 'propagate': False |
398 | 408 | }, |
399 | | - 'allauth': { |
400 | | - 'handlers': ['console_dev', 'console_prod'], |
401 | | - 'level': 'DEBUG', |
402 | | - 'propagate': True, |
403 | | - }, |
404 | | - 'google_helpers': { |
405 | | - 'handlers': ['console_dev', 'console_prod'], |
406 | | - 'level': 'DEBUG', |
| 409 | + 'django.request': { |
| 410 | + 'handlers': ['mail_admins'], |
| 411 | + 'level': 'ERROR', |
407 | 412 | 'propagate': True, |
408 | | - }, |
| 413 | + } |
409 | 414 | }, |
410 | 415 | } |
411 | 416 |
|
|
0 commit comments