From 926935af56b211539cc92f851cb00714a698c644 Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Thu, 12 Sep 2019 11:35:23 +0200 Subject: [PATCH] Enhance logging. --- README.md | 4 +--- config.py | 8 +++++++- docker-compose.yml | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 64ec690d..6ea5d86c 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,8 @@ As a last step texts can be loaded into an information retrieval system to query ## Setup 0. **Create log files** -``` basj +``` bash mkdir /logs -touch /logs/opaque_flask.log -touch /logs/opaque_daemon.log ``` diff --git a/config.py b/config.py index 443a94f2..7ed0590d 100644 --- a/config.py +++ b/config.py @@ -36,11 +36,17 @@ class DevelopmentConfig(Config): os.environ.get('POSTGRES_PASSWORD'), os.environ.get('POSTGRES_DB_NAME') ) + if not os.path.isfile('logs/opaque_web.log'): + file_path = os.path.join(os.getcwd(), 'logs/opaque_web.log') + log = open(file_path, 'w+') + log.close() log_format = ("%(asctime)s - %(levelname)s - %(name)s - " "%(filename)s - %(lineno)d - %(message)s") - logging.basicConfig(filename='logs/opaque_flask.log', level='WARNING', + logging.basicConfig(filename='logs/opaque_web.log', level='WARNING', format=log_format, datefmt='%Y-%m-%d %H:%M:%S', filemode='w') + logger = logging.getLogger(__name__) + logger.info('Logging has started.') class TestingConfig(Config): diff --git a/docker-compose.yml b/docker-compose.yml index 9079af4b..7b490b54 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,7 +19,7 @@ services: - /mnt/opaque:/mnt/opaque - ./app:/home/opaque/app - ./config.py:/home/opaque/config.py - - ./logs/opaque_flask.log:/home/opaque/logs/opaque_flask.log + - ./logs:/home/opaque/logs - ./migrations:/home/opaque/migrations - ./opaque.py:/home/opaque/opaque.py daemon: