Commit 9259da36 authored by david's avatar david
Browse files

SoC for config and logger. #72

parent 04135d87
......@@ -100,23 +100,6 @@ class AuraConfig:
self.logger.warning("Key " + key + " not found in configfile " + self.ini_path + "!")
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]
......@@ -161,3 +144,12 @@ class AuraConfig:
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():
logger = None
def __init__(self, config, name="AuraEngine"):
"""
Constructor to create a new logger defined by
......@@ -47,26 +46,42 @@ class AuraLogger():
name (String): The name of the logger
"""
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.
Args:
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.setLevel(lvl)
if not self.logger.hasHandlers():
# 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)
# create stream handler for logger
......@@ -87,6 +102,6 @@ class AuraLogger():
self.logger.addHandler(file_handler)
self.logger.addHandler(stream_handler)
self.logger.critical("ADDED HANDLERS")
self.logger.debug("ADDED HANDLERS")
else:
self.logger.critical("REUSED LOGGER")
\ No newline at end of file
self.logger.debug("REUSED LOGGER")
\ No newline at end of file
Markdown is supported
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