Skip to content

Commit 2f09c93

Browse files
updated
1 parent 57d5556 commit 2f09c93

File tree

7 files changed

+52
-4
lines changed

7 files changed

+52
-4
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ DB_PORT=5432
55
DB_NAME=term_db
66
DB_USER=sadilar
77
DB_PASSWORD=sadilar
8-
LOGGING_FILE=logs/debug.log
8+
LOGGING_FILE=debug.log
99
LOGGING_HANDLERS_LEVEL=INFO
1010
LOGGING_LOGGERS_LEVEL=INFO
1111
LOGGING_LOGGERS_DJANGO_LEVEL=INFO

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ db.sqlite3
1616
db.sqlite3-journal
1717
media
1818

19-
# macOS template
20-
# General
19+
# General Files
2120
.DS_Store
2221
.AppleDouble
2322
.LSOverride
@@ -30,7 +29,10 @@ venv/
3029
ENV/
3130
env.bak/
3231
venv.bak/
32+
33+
#folders
3334
app/static_files/
3435
/app/documents/
3536
app/media/
3637
/app/logging/
38+
/logging/

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,7 @@ dev-quick-install:
112112
@make load-fixtures
113113
echo "Creating superuser"
114114
@make create-super-user
115+
116+
shell:
117+
clear
118+
docker exec -it sadilar-terminology-web bash

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,11 @@ https://django-simple-history.readthedocs.io/en/latest/
3737
### environment variables
3838

3939
please use .env.example as example
40+
41+
42+
## Production
43+
44+
Docker Volumes for production:
45+
46+
/media
47+
/logs

app/app/settings.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@
164164

165165
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
166166

167+
LOGGING_FOLDER_DEFAULT = os.path.abspath(os.path.join("/logging/"))
168+
169+
# Check if the application is under testing
170+
if "test" in sys.argv:
171+
DEBUG = False
172+
else:
173+
DEBUG = True
167174

168175
if DEBUG:
169176
LOGGING = {
@@ -190,7 +197,9 @@
190197
"file": {
191198
"level": os.environ.get("LOGGING_HANDLERS_LEVEL", "WARNING"),
192199
"class": "logging.FileHandler",
193-
"filename": os.environ.get("LOGGING_FILE", "logging/debug.log"),
200+
"filename": os.path.join(
201+
LOGGING_FOLDER_DEFAULT, os.environ.get("LOGGING_FILE", "debug.log")
202+
),
194203
"formatter": "verbose",
195204
},
196205
},

app/general/tests/test_logging.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import logging
2+
import os
3+
import sys
4+
5+
from django.test import TestCase
6+
7+
8+
class LoggingTest(TestCase):
9+
def setUp(self):
10+
LOGGING_FOLDER_DEFAULT = os.path.abspath(os.path.join("/logging/"))
11+
self.logger = logging.getLogger("django")
12+
self.log_file = os.path.join(LOGGING_FOLDER_DEFAULT, "debug.log")
13+
14+
def test_log_file_created(self):
15+
"""Test if the log file is created."""
16+
self.logger.error("This is a test error message.")
17+
18+
self.assertTrue(os.path.exists(self.log_file))
19+
20+
def test_log_message(self):
21+
"""Test if the log message is written to the file."""
22+
with open(self.log_file, "r") as f:
23+
content = f.read()
24+
self.assertIn("This is a test error message.", content)

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ services:
2222
command: python manage.py runserver 0.0.0.0:8000
2323
volumes:
2424
- ./app:/app
25+
- ./logging:/logging
2526
ports:
2627
- "8000:8000"
2728
depends_on:

0 commit comments

Comments
 (0)