#!/usr/bin/python3
from nitsi.test import test
+from nitsi.logger import init_logging
import logging
logger = logging.getLogger("nitsi")
logger.setLevel(logging.DEBUG)
-# create file handler which logs even debug messages
-fh = logging.FileHandler('nitsi.log')
-fh.setLevel(logging.DEBUG)
# create console handler with a higher log level
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
-fh.setFormatter(formatter)
ch.setFormatter(formatter)
# add the handlers to the logger
-logger.addHandler(fh)
logger.addHandler(ch)
if __name__ == "__main__":
if args.version:
logger.info("nitsi version: {}".format("@PACKAGE_VERSION@"))
else:
- currenttest = test(args.dir)
+ log_dir = init_logging(args.dir)
+ # We now going to log everything to log_dir/genaral.log
+ fh = logging.FileHandler("{}/general.log".format(log_dir))
+ fh.setLevel(logging.DEBUG)
+ logger.addHandler(fh)
+ logger.debug("We now logging everything to {}/general.log".format(log_dir))
+
+ currenttest = test(args.dir, log_dir)
currenttest.read_settings()
currenttest.virtual_environ_setup()
currenttest.load_recipe()
--- /dev/null
+#!/usr/bin/python3
+
+import logging
+import os
+import time
+
+logger = logging.getLogger("nitsi.logger")
+
+class Logger_Exeception(BaseException):
+ pass
+
+# This function should create the necessary folders
+# and touch the logging files
+def init_logging(path):
+ logger.debug("Init logging directory")
+ if not os.path.isdir(path):
+ logger.error("{} is not a valid directory".format(path))
+
+ try:
+ path = os.path.abspath(path)
+ except BaseException as e:
+ logger.error("Failed to get the absolute path for: {}".format(path))
+
+ log_dir = "{}/log".format(path)
+
+ if not os.path.exists(log_dir):
+ os.mkdir(log_dir)
+
+ time_dir = log_dir + "/" + time.strftime("%Y-%m-%d_%H-%M-%S" ,time.gmtime(time.time()))
+
+ if os.path.exists(time_dir):
+ logger.error("Path {} alreday exist".format(time_dir))
+ raise Logger_Exeception
+ else:
+ os.mkdir(time_dir)
+
+ return time_dir
logger = logging.getLogger("nitsi.test")
class test():
- def __init__(self, path):
+ def __init__(self, path, log_path):
try:
self.path = os.path.abspath(path)
self.log = logger.getChild(os.path.basename(self.path))