From 3a94e857aaa6456bb2c1614216fe456574335492 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Thu, 21 Jan 2021 19:38:10 +0100 Subject: [PATCH] Adaption to new logging --- .gitignore | 23 +++++++++++++++++ config_example/config.py | 3 +++ fstools | 2 +- geo | 2 +- main/settings.py | 55 ++++++++++++++++------------------------ media | 2 +- mycreole | 2 +- pygal | 2 +- readme.txt | 18 ------------- stringtools | 2 +- users | 2 +- 11 files changed, 55 insertions(+), 58 deletions(-) delete mode 100644 readme.txt diff --git a/.gitignore b/.gitignore index 9d07e38..32492c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ config.py data/ +venv .settings # ---> Python @@ -119,3 +120,25 @@ dmypy.json # Pyre type checker .pyre/ +# ---> Linux +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +# ---> Backup +*.bak +*.gho +*.ori +*.orig +*.tmp + diff --git a/config_example/config.py b/config_example/config.py index ce928c4..ae76abd 100644 --- a/config_example/config.py +++ b/config_example/config.py @@ -6,6 +6,9 @@ BASE_DIR = os.path.dirname(os.path.abspath(__file__)) # General settings # +# APP_NAME is used for logging +APP_NAME = 'pygal' + # SECURITY WARNING: don't run with debug turned on in production! # DEBUG = False diff --git a/fstools b/fstools index ada1f74..f5da43b 160000 --- a/fstools +++ b/fstools @@ -1 +1 @@ -Subproject commit ada1f74d4c05a35bad9d2b258f3d0b4ccdfd1653 +Subproject commit f5da43b01631147dace87242a94227acfb3e9bc5 diff --git a/geo b/geo index f59b19e..11166bb 160000 --- a/geo +++ b/geo @@ -1 +1 @@ -Subproject commit f59b19ed1fd2a64735ca477fdb1fba24681e8879 +Subproject commit 11166bb27ad2335f7812fcb88c788397f5106751 diff --git a/main/settings.py b/main/settings.py index 665fdcc..1bfe0be 100644 --- a/main/settings.py +++ b/main/settings.py @@ -11,11 +11,17 @@ https://docs.djangoproject.com/en/3.0/ref/settings/ """ import config +from logging.handlers import SocketHandler as _SocketHandler import os import stat import sys import random +try: + from config import APP_NAME as ROOT_LOGGER_NAME +except ImportError: + ROOT_LOGGER_NAME = 'root' + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) # @@ -64,7 +70,7 @@ for property_name in USER_CONFIG_DEFAULTS: if SECRET_KEY is None: chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' s_key = ''.join([random.choice(chars) for n in range(50)]) - secret_key_warning = "You need to create a config.py file including at least a SECRET_KEY definition (e.g.: %s)." % repr(s_key) + secret_key_warning = "You need to create a config.py file including at least a SECRET_KEY definition (e.g.: --> %s <--)." % repr(s_key) raise KeyError(secret_key_warning) @@ -194,7 +200,14 @@ PERSISTENT_SESSION_VARIABLES = [SESSION_KEY_THUMBNAIL_SIZE, SESSION_KEY_WEBNAIL_ # Logging Configuration # -default_handler = ['console_long'] if DEBUG else ['console'] +class DjangoSocketHandler(_SocketHandler): + def emit(self, record): + if hasattr(record, 'request'): + record.request = None + return super().emit(record) + + +default_handler = ['socket'] if DEBUG else ['console'] # LOGGING = { 'version': 1, @@ -217,46 +230,22 @@ File "%(pathname)s", line %(lineno)d, in %(funcName)s 'class': 'logging.StreamHandler', 'formatter': 'short', }, - 'console_long': { + 'socket': { 'level': 'DEBUG', - 'class': 'logging.StreamHandler', - 'formatter': 'long', + 'class': 'main.settings.DjangoSocketHandler', + 'host': '127.0.0.1', + 'port': 19996, }, }, 'loggers': { - 'AUTH': { + 'django': { 'handlers': default_handler, 'level': 'INFO', 'propagate': False, }, - 'APP': { + ROOT_LOGGER_NAME: { 'handlers': default_handler, - 'level': 'INFO', - 'propagate': False, - }, - 'CACHING': { - 'handlers': default_handler, - 'level': 'INFO', - 'propagate': False, - }, - 'WHOOSH': { - 'handlers': default_handler, - 'level': 'INFO', - 'propagate': False, - }, - 'FSTOOLS': { - 'handlers': default_handler, - 'level': 'INFO', - 'propagate': False, - }, - 'GEO': { - 'handlers': default_handler, - 'level': 'INFO', - 'propagate': False, - }, - 'MEDIA': { - 'handlers': default_handler, - 'level': 'INFO', + 'level': 'DEBUG' if DEBUG else 'INFO', 'propagate': False, }, }, diff --git a/media b/media index 0a67ebe..abcf63d 160000 --- a/media +++ b/media @@ -1 +1 @@ -Subproject commit 0a67ebeb4810eb00f422745b4a21ee420fc31c85 +Subproject commit abcf63d02e866c3832d014c54f2a95acdfb7d304 diff --git a/mycreole b/mycreole index dd0edc2..5f30383 160000 --- a/mycreole +++ b/mycreole @@ -1 +1 @@ -Subproject commit dd0edc2d56c2c234be32fa76e3bd5b6b4f38a69f +Subproject commit 5f30383c83b0ea94341b999c489a34f2e7d57f80 diff --git a/pygal b/pygal index 8420686..114a82e 160000 --- a/pygal +++ b/pygal @@ -1 +1 @@ -Subproject commit 84206862234752932d7c30daf82807c1e9fff67a +Subproject commit 114a82e1768d3fbf8a83afb61b2f19c271b8868b diff --git a/readme.txt b/readme.txt deleted file mode 100644 index 44742c2..0000000 --- a/readme.txt +++ /dev/null @@ -1,18 +0,0 @@ -1. Setupt venev - * virtualenv -p /usr/bin/python3 pygal-venv - * ln -s pygal-venv/bin/activate - * source activate - * Sometimes upgrades are needed: pip list --outdated | cut -d ' ' -f 1 | xargs pip install $1 --upgrade - * pip install -r requirements.txt -2. python manage.py migrate -3. python manage.py createsuperuser -4. Set SECRET:KEY in config.py -5. Set ITEM_ROOT in config.py to your item target path, otherwise the example_data is used -6. python manage.py collectstatic -7. chgrp www-data . && chmod 770 . -8. chgrp www-data db.sqlite3 && chmod 664 db.sqlite3 -9. chgrp www-data -R data -9.1. find data -type d -exec chmod 775 "{}" \; -9.2. find data -type f -exec chmod 664 "{}" \; - -x. Run server by command "python manage.py runserver 0.0.0.0:8000" or add App to apache diff --git a/stringtools b/stringtools index d5f9931..c1d9cf4 160000 --- a/stringtools +++ b/stringtools @@ -1 +1 @@ -Subproject commit d5f9931bcab942ac84d8f09b1559995da0d2676c +Subproject commit c1d9cf49c34cc6c97cfb372eec4a30f0188181f9 diff --git a/users b/users index 8cf6446..0827a53 160000 --- a/users +++ b/users @@ -1 +1 @@ -Subproject commit 8cf64464ba094df60fe81442dd0d728075368344 +Subproject commit 0827a5311fdbbef689365c6db5762881e048ba9c