commit 1bdc90c0b6f91c037505c05ab34c257dda5b4855
Author: David Friesecký <frieseck@students.zcu.cz>
Date:   Wed Apr 21 11:55:44 2021 +0200

    Re #8570 - Setted configuration of logging

diff --git a/app.py b/app.py
index 7e016b3..a2aba86 100644
--- a/app.py
+++ b/app.py
@@ -80,6 +80,8 @@ def initialize_app(application) -> bool:
     injector = Injector(modules)
     FlaskInjector(app=application, modules=modules)
 
+    configuration.configure_logging()
+
     # There's a little dependency on the CryptoService, which is not a pretty thing from
     # architectural point of view. However it is only a minimal piece of code and
     # it makes sense to do it in this way instead of trying to run openssl via subprocess here
diff --git a/src/config/configuration.py b/src/config/configuration.py
index 3654a49..1e99558 100644
--- a/src/config/configuration.py
+++ b/src/config/configuration.py
@@ -5,6 +5,7 @@ import logging
 from injector import singleton
 
 from src.constants import DEFAULT_CONNECTION_STRING, TEST_DATABASE_FILE, DEFAULT_SERVER_BASE_URL
+from src.constants import LOG_FILE_LOCATION, LOG_FORMAT
 
 DATABASE_SECTION = "Database"
 DATABASE_CONNECTION_STRING = "ConnectionString"
@@ -12,9 +13,6 @@ DATABASE_CONNECTION_STRING = "ConnectionString"
 SERVER_SECTION = "Server"
 SERVER_BASE_URL = "ServerBaseURL"
 
-LOG_FILE = "application.log"
-LOG_FORMAT = "%(levelname)-8s %(asctime)s - %(message)s"
-
 
 class Configuration:
     """
@@ -68,8 +66,8 @@ def configure_env_variable(binder):
     binder.bind(Configuration, to=app_configuration, scope=singleton)
 
 
-def configure_logging(self):
-    logging.basicConfig(filename=LOG_FILE,
+def configure_logging():
+    logging.basicConfig(filename=LOG_FILE_LOCATION.shortest_relative_path(),
                         filemode='a+',
                         format=LOG_FORMAT,
                         level=logging.DEBUG)
diff --git a/src/constants.py b/src/constants.py
index 928a93c..cb7e77f 100644
--- a/src/constants.py
+++ b/src/constants.py
@@ -6,6 +6,10 @@ DATABASE_FILE = "db/database_sqlite.db"
 DATABASE_FILE_LOCATION = FileAnchor("aswi2021jmsd", DATABASE_FILE)
 DATETIME_FORMAT = "%d.%m.%Y %H:%M:%S"
 
+LOG_FILE = "log/application.log"
+LOG_FILE_LOCATION = FileAnchor("aswi2021jmsd", LOG_FILE)
+LOG_FORMAT = "%(levelname)-8s %(asctime)s - %(message)s"
+
 REV_REASON_UNSPECIFIED = "unspecified"
 
 # Types of certificates
diff --git a/src/utils/logger.py b/src/utils/logger.py
index 35b3d76..0462a35 100644
--- a/src/utils/logger.py
+++ b/src/utils/logger.py
@@ -1,24 +1,40 @@
+import inspect
 import logging
+from pathlib import Path
 
 
 class Logger:
 
     @staticmethod
-    def debug(layer: str, message: str):
-        logging.debug(f'{layer}: {message}')
+    def get_names():
+        stack = inspect.stack()
+        file_name = inspect.getfile(stack[2][0].f_locals["self"].__class__)
+        class_name = stack[2][0].f_locals["self"].__class__.__name__
+        function_name = stack[2][0].f_code.co_name
+
+        return file_name, class_name, function_name
+
+    @staticmethod
+    def debug(message: str):
+        names = Logger.get_names()
+        logging.debug(f'{Path(names[0]).name}[{names[1]}.{names[2]}()]: {message}')
 
     @staticmethod
-    def info(layer: str, message: str):
-        logging.info(f'{layer}: {message}')
+    def info(message: str):
+        names = Logger.get_names()
+        logging.info(f'{Path(names[0]).name}[{names[1]}.{names[2]}()]: {message}')
 
     @staticmethod
-    def warning(layer: str, message: str):
-        logging.warning(f'{layer}: {message}')
+    def warning(message: str):
+        names = Logger.get_names()
+        logging.warning(f'{Path(names[0]).name}[{names[1]}.{names[2]}()]: {message}')
 
     @staticmethod
-    def error(layer: str, message: str):
-        logging.error(f'{layer}: {message}')
+    def error(message: str):
+        names = Logger.get_names()
+        logging.error(f'{Path(names[0]).name}[{names[1]}.{names[2]}()]: {message}')
 
     @staticmethod
-    def critical(layer: str, message: str):
-        logging.critical(f'{layer}: {message}')
+    def critical(message: str):
+        names = Logger.get_names()
+        logging.critical(f'{Path(names[0]).name}[{names[1]}.{names[2]}()]: {message}')
