Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-gray-tangent committed May 8, 2024
1 parent 57d5556 commit 2f09c93
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ DB_PORT=5432
DB_NAME=term_db
DB_USER=sadilar
DB_PASSWORD=sadilar
LOGGING_FILE=logs/debug.log
LOGGING_FILE=debug.log
LOGGING_HANDLERS_LEVEL=INFO
LOGGING_LOGGERS_LEVEL=INFO
LOGGING_LOGGERS_DJANGO_LEVEL=INFO
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ db.sqlite3
db.sqlite3-journal
media

# macOS template
# General
# General Files
.DS_Store
.AppleDouble
.LSOverride
Expand All @@ -30,7 +29,10 @@ venv/
ENV/
env.bak/
venv.bak/

#folders
app/static_files/
/app/documents/
app/media/
/app/logging/
/logging/
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,7 @@ dev-quick-install:
@make load-fixtures
echo "Creating superuser"
@make create-super-user

shell:
clear
docker exec -it sadilar-terminology-web bash
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ https://django-simple-history.readthedocs.io/en/latest/
### environment variables

please use .env.example as example


## Production

Docker Volumes for production:

/media
/logs
11 changes: 10 additions & 1 deletion app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

LOGGING_FOLDER_DEFAULT = os.path.abspath(os.path.join("/logging/"))

# Check if the application is under testing
if "test" in sys.argv:
DEBUG = False
else:
DEBUG = True

if DEBUG:
LOGGING = {
Expand All @@ -190,7 +197,9 @@
"file": {
"level": os.environ.get("LOGGING_HANDLERS_LEVEL", "WARNING"),
"class": "logging.FileHandler",
"filename": os.environ.get("LOGGING_FILE", "logging/debug.log"),
"filename": os.path.join(
LOGGING_FOLDER_DEFAULT, os.environ.get("LOGGING_FILE", "debug.log")
),
"formatter": "verbose",
},
},
Expand Down
24 changes: 24 additions & 0 deletions app/general/tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import logging
import os
import sys

from django.test import TestCase


class LoggingTest(TestCase):
def setUp(self):
LOGGING_FOLDER_DEFAULT = os.path.abspath(os.path.join("/logging/"))
self.logger = logging.getLogger("django")
self.log_file = os.path.join(LOGGING_FOLDER_DEFAULT, "debug.log")

def test_log_file_created(self):
"""Test if the log file is created."""
self.logger.error("This is a test error message.")

self.assertTrue(os.path.exists(self.log_file))

def test_log_message(self):
"""Test if the log message is written to the file."""
with open(self.log_file, "r") as f:
content = f.read()
self.assertIn("This is a test error message.", content)
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ services:
command: python manage.py runserver 0.0.0.0:8000
volumes:
- ./app:/app
- ./logging:/logging
ports:
- "8000:8000"
depends_on:
Expand Down

0 comments on commit 2f09c93

Please sign in to comment.