Skip to content

Commit ce1f6cd

Browse files
added basic logging and updated environment variables
1 parent 835f688 commit ce1f6cd

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

.env.example

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SECRET_KEY='django-insecure-w!h85bp^$$e8gm%c23r!0%9i7yzd=6w$$s&ic+6!%306&kj8@k*5'
2+
DEBUG=True
3+
DB_HOST=db
4+
DB_PORT=5432
5+
DB_NAME=term_db
6+
DB_USER=sadilar
7+
DB_PASSWORD=sadilar
8+
LOGGING_FILE=logs/debug.log
9+
LOGGING_HANDLERS_LEVEL=INFO
10+
LOGGING_LOGGERS_LEVEL=INFO

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,25 @@ About the project:
2424
3. Run `make run` to run the docker container
2525
4. Run `make stop` to stop the docker container
2626

27+
## Production
28+
2729

2830
### Plugins installed
2931
#### Django Simple History
3032

3133
https://django-simple-history.readthedocs.io/en/latest/
34+
35+
#### Basic setup for production
36+
37+
### environment variables
38+
39+
please use .env.example as example
40+
41+
## Suggested folder structure
42+
43+
Add the following folders to the Docker container:
44+
45+
* /documents
46+
* /static_files
47+
* /logos
48+
* /media

app/app/settings.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,52 @@
154154
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
155155

156156
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
157+
158+
159+
if DEBUG:
160+
LOGGING = {
161+
"version": 1,
162+
"disable_existing_loggers": False,
163+
"handlers": {
164+
"console": {
165+
"class": "logging.StreamHandler",
166+
},
167+
},
168+
"root": {
169+
"handlers": ["console"],
170+
"level": "DEBUG",
171+
},
172+
}
173+
else:
174+
LOGGING = {
175+
"version": 1,
176+
"disable_existing_loggers": False,
177+
"handlers": {
178+
"console": {
179+
"class": "logging.StreamHandler",
180+
},
181+
"file": {
182+
"level": os.environ.get("LOGGING_HANDLERS_LEVEL", "WARNING"),
183+
"class": "logging.FileHandler",
184+
"filename": os.environ.get("LOGGING_FILE", "WARNING"),
185+
"formatter": "verbose",
186+
},
187+
},
188+
"root": {
189+
"handlers": ["console", "file"],
190+
"level": os.environ.get("LOGGING_LOGGERS_LEVEL", "WARNING"),
191+
},
192+
"loggers": {
193+
"django": {
194+
"handlers": ["file"],
195+
"level": os.environ.get("LOGGING_LOGGERS_CONSOLE_LEVEL", "WARNING"),
196+
"propagate": True,
197+
},
198+
},
199+
"formatters": {
200+
"verbose": {
201+
"format": "{asctime} {levelname} - {name} {module}.py (line: {lineno:d}). - {message}",
202+
"style": "{",
203+
},
204+
},
205+
}

docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ services:
3636
- DB_NAME=term_db # see POSTGRES_DB above
3737
- DB_USER=sadilar # see POSTGRES_USER above
3838
- DB_PASSWORD=sadilar # see POSTGRES_PASSWORD above
39+
- LOGGING_FILE=logs/debug.log
40+
- LOGGING_HANDLERS_LEVEL=WARNING
41+
- LOGGING_LOGGERS_LEVEL=WARNING
42+
- LOGGING_LOGGERS_CONSOLE_LEVEL=WARNING

0 commit comments

Comments
 (0)