Commit 9259da36 authored by David Trattnig's avatar David Trattnig
Browse files

SoC for config and logger. #72

parent 04135d87
...@@ -100,23 +100,6 @@ class AuraConfig: ...@@ -100,23 +100,6 @@ class AuraConfig:
self.logger.warning("Key " + key + " not found in configfile " + self.ini_path + "!") self.logger.warning("Key " + key + " not found in configfile " + self.ini_path + "!")
return None return None
if key == "loglevel":
loglvl = self.__dict__[key]
if loglvl == "debug":
return logging.DEBUG
elif loglvl == "info":
return logging.INFO
elif loglvl == "warning":
return logging.WARNING
elif loglvl == "error":
return logging.ERROR
else:
return logging.CRITICAL
if key == "debug":
return self.__dict__[key].count("y")
return self.__dict__[key] return self.__dict__[key]
...@@ -161,3 +144,12 @@ class AuraConfig: ...@@ -161,3 +144,12 @@ class AuraConfig:
self.set(key, v) self.set(key, v)
def to_abs_path(self, path):
"""
Transforms any given (relative) path to an absolute paths
derived from the project root.
"""
if path.startswith("/"):
return path
else:
return self.get("install_dir") + "/" + path
\ No newline at end of file
...@@ -37,7 +37,6 @@ class AuraLogger(): ...@@ -37,7 +37,6 @@ class AuraLogger():
logger = None logger = None
def __init__(self, config, name="AuraEngine"): def __init__(self, config, name="AuraEngine"):
""" """
Constructor to create a new logger defined by Constructor to create a new logger defined by
...@@ -47,26 +46,42 @@ class AuraLogger(): ...@@ -47,26 +46,42 @@ class AuraLogger():
name (String): The name of the logger name (String): The name of the logger
""" """
self.config = config self.config = config
self.__create_logger(name) lvl = self.get_log_level()
self.create_logger(name, lvl)
def get_log_level(self):
"""
Retrieves the configured log level (default=INFO).
"""
lvl = self.config.get("log_level")
if lvl == "debug":
return logging.DEBUG
elif lvl == "info":
return logging.INFO
elif lvl == "warning":
return logging.WARNING
elif lvl == "error":
return logging.ERROR
else:
return logging.CRITICAL
def __create_logger(self, name): def create_logger(self, name, lvl):
""" """
Creates the logger instance for the given name. Creates the logger instance for the given name.
Args: Args:
name (String): The name of the logger name (String): The name of the logger
lvl (Enum): The logging level
""" """
lvl = self.config.get("loglevel")
# create logger
self.logger = logging.getLogger(name) self.logger = logging.getLogger(name)
self.logger.setLevel(lvl) self.logger.setLevel(lvl)
if not self.logger.hasHandlers(): if not self.logger.hasHandlers():
# create file handler for logger # create file handler for logger
file_handler = logging.FileHandler(self.config.get("logdir") + "/"+name+".log") file_handler = logging.FileHandler(self.config.get("log_dir") + "/"+name+".log")
file_handler.setLevel(lvl) file_handler.setLevel(lvl)
# create stream handler for logger # create stream handler for logger
...@@ -87,6 +102,6 @@ class AuraLogger(): ...@@ -87,6 +102,6 @@ class AuraLogger():
self.logger.addHandler(file_handler) self.logger.addHandler(file_handler)
self.logger.addHandler(stream_handler) self.logger.addHandler(stream_handler)
self.logger.critical("ADDED HANDLERS") self.logger.debug("ADDED HANDLERS")
else: else:
self.logger.critical("REUSED LOGGER") self.logger.debug("REUSED LOGGER")
\ No newline at end of file \ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment