Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ def _normalize_google_redirect_uri(raw_uri: str, backend_base_url: str) -> str:
STATIC_URL = 'static/'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

LOG_DIR = BASE_DIR / 'logs'
os.makedirs(LOG_DIR, exist_ok=True)

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
Expand Down Expand Up @@ -174,6 +177,81 @@ def _normalize_google_redirect_uri(raw_uri: str, backend_base_url: str) -> str:
# Allow all origins in development
CORS_ALLOW_ALL_ORIGINS = True

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '[{levelname}] {asctime} {name}: {message}',
'style': '{',
},
'simple': {
'format': '{levelname}: {message}',
'style': '{',
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'stream': 'ext://sys.stdout',
'formatter': 'simple',
},
'file': {
'class': 'logging.handlers.RotatingFileHandler',
'filename': str(LOG_DIR / 'leadorbit.log'),
'maxBytes': 5 * 1024 * 1024,
'backupCount': 3,
'formatter': 'verbose',
},
},
'root': {
'handlers': ['console', 'file'],
'level': 'INFO',
},
'loggers': {
'django': {
'handlers': ['console', 'file'],
'level': 'INFO',
'propagate': False,
},
'django.db.backends': {
'handlers': ['console', 'file'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False,
},
'celery': {
'handlers': ['console', 'file'],
'level': 'INFO',
'propagate': False,
},
'celery.app.trace': {
'handlers': ['console', 'file'],
'level': 'ERROR',
'propagate': False,
},
'campaigns': {
'handlers': ['console', 'file'],
'level': 'INFO',
'propagate': False,
},
'leads': {
'handlers': ['console', 'file'],
'level': 'INFO',
'propagate': False,
},
'tenants': {
'handlers': ['console', 'file'],
'level': 'INFO',
'propagate': False,
},
'users': {
'handlers': ['console', 'file'],
'level': 'INFO',
'propagate': False,
},
},
}

# Gemini API Key
GEMINI_API_KEY = os.getenv('GEMINI_API_KEY', _read_local_env_value('GEMINI_API_KEY', ''))
OPENROUTER_API_KEY = os.getenv('OPENROUTER_API_KEY', _read_local_env_value('OPENROUTER_API_KEY', ''))
Expand Down
13 changes: 13 additions & 0 deletions backend/backend/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.test import SimpleTestCase
from django.conf import settings as django_settings


class LoggingSettingsTests(SimpleTestCase):
def test_logging_config_includes_console_file_and_backend_loggers(self):
logging_config = django_settings.LOGGING

self.assertIn('console', logging_config['handlers'])
self.assertIn('file', logging_config['handlers'])
self.assertIn('django.db.backends', logging_config['loggers'])
self.assertIn('celery.app.trace', logging_config['loggers'])
self.assertEqual(logging_config['root']['handlers'], ['console', 'file'])