Skip to content

Commit 2bf2cc7

Browse files
Merge pull request #7 from zeeshanrafiqrana/V.0.0.2
[TL-4] Djnago Loggin and Sentry Configuration
2 parents 9eeff91 + 58e3812 commit 2bf2cc7

File tree

7 files changed

+111
-10
lines changed

7 files changed

+111
-10
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ name = "pypi"
77
django = "==4.2.6"
88
python-environ = "==0.4.54"
99
psycopg2-binary = "==2.9.9"
10+
sentry-sdk = "==1.34.0"
1011

1112
[dev-packages]
1213

Pipfile.lock

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ Django PropelPro is your indispensable tool for launching Django projects with r
3636
```
3737

3838
5. **Explore**: Access the admin panel at `http://localhost:8000/admin` and the app at `http://localhost:8000`.
39-
39+
6. **Sentry Logging**: Add Sentry DSN in .env. Update your all configuration django.
40+
```bash
41+
SENTRY_IO_DSN=<SENTRY_DSN>
42+
```
4043
## Contributions
4144

4245
We welcome contributions to make Django PropelPro even better! Here's how you can get involved:

apps/users/urls.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.urls import path
2+
3+
from . import views
4+
5+
urlpatterns = [
6+
path('sentry-debug/', views.sentry_debug_view),
7+
]

apps/users/views.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
import logging
12
from django.shortcuts import render
23

4+
logger = logging.getLogger("apps.users.views")
5+
6+
37
# Create your views here.
8+
def sentry_debug_view(request):
9+
logger.info("This is an informational message.")
10+
logger.debug("This is a debug message.")
11+
logger.warning("This is a warning message.")
12+
logger.error("This is an error message.")
13+
logger.critical("This is a critical message.")

swiftstart/settings.py

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
import os
1313
import environ
1414
from pathlib import Path
15+
1516
from modules.manifest import get_modules
1617

1718

19+
1820
# Build paths inside the project like this: BASE_DIR / 'subdir'.
1921
BASE_DIR = Path(__file__).resolve().parent.parent
2022
env = environ.Env()
@@ -90,17 +92,21 @@
9092
# Database
9193
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
9294

93-
DATABASES = {
94-
'default': {
95-
'ENGINE': 'django.db.backends.sqlite3',
96-
'NAME': BASE_DIR / 'db.sqlite3',
97-
}
98-
}
99-
10095
if env.str("DATABASE_URL", default=None):
10196
DATABASES = {
10297
'default': env.db()
10398
}
99+
else:
100+
DATABASES = {
101+
"default": {
102+
"ENGINE": "django.db.backends.postgresql_psycopg2",
103+
"NAME": env("DJANGO_DATABASE_NAME", default="propelpro"),
104+
"USER": env("DJANGO_DATABASE_USER", default="postgres"),
105+
"PASSWORD": env("DJANGO_DATABASE_PASSWORD", default="***"),
106+
"HOST": env("DJANGO_DATABASE_HOST", default="localhost"),
107+
"PORT": env("DJANGO_DATABASE_PORT", default="5432"),
108+
}
109+
}
104110

105111

106112
# Password validation
@@ -145,3 +151,49 @@
145151
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
146152

147153
AUTH_USER_MODEL = "users.User"
154+
155+
156+
# Django logging configuration and separators
157+
158+
LOGGING = {
159+
"version": 1,
160+
"disable_existing_loggers": False,
161+
"formatters": {
162+
"verbose": {
163+
"format": '[{asctime}] {levelname} "{name}" {message}',
164+
"style": "{",
165+
},
166+
},
167+
"handlers": {
168+
"console": {
169+
"level": "DEBUG",
170+
"class": "logging.StreamHandler",
171+
"formatter": "verbose",
172+
},
173+
},
174+
"loggers": {
175+
"django": {
176+
"handlers": ["console"],
177+
"level": env("DJANGO_LOG_LEVEL", default="INFO"),
178+
},
179+
"swiftstart": {
180+
"handlers": ["console"],
181+
"level": env("DJANGO_PROJECT_LOG_LEVEL", default="INFO"),
182+
},
183+
},
184+
}
185+
186+
# Sentry Alert configurations
187+
188+
SENTRY_IO_DSN = env("SENTRY_IO_DSN", default="")
189+
190+
if SENTRY_IO_DSN:
191+
import sentry_sdk
192+
from sentry_sdk.integrations.django import DjangoIntegration
193+
194+
sentry_sdk.init(
195+
dsn=SENTRY_IO_DSN,
196+
integrations=[DjangoIntegration()],
197+
traces_sample_rate=1.0,
198+
send_default_pii=True,
199+
)

swiftstart/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
1616
"""
1717
from django.contrib import admin
18-
from django.urls import path
18+
from django.urls import path, include
1919

2020
urlpatterns = [
2121
path('admin/', admin.site.urls),
22+
path("users/", include("apps.users.urls")),
2223
]

0 commit comments

Comments
 (0)