Log exeptions when we try to login
[nitsi.git] / src / nitsi / logger.py
CommitLineData
d7036f7b
JS
1#!/usr/bin/python3
2
3import logging
4import os
5import time
6
7logger = logging.getLogger("nitsi.logger")
8
9class Logger_Exeception(BaseException):
10 pass
11
12# This function should create the necessary folders
13# and touch the logging files
14def init_logging(path):
15 logger.debug("Init logging directory")
16 if not os.path.isdir(path):
17 logger.error("{} is not a valid directory".format(path))
18
19 try:
20 path = os.path.abspath(path)
21 except BaseException as e:
22 logger.error("Failed to get the absolute path for: {}".format(path))
23
24 log_dir = "{}/log".format(path)
25
26 if not os.path.exists(log_dir):
27 os.mkdir(log_dir)
28
29 time_dir = log_dir + "/" + time.strftime("%Y-%m-%d_%H-%M-%S" ,time.gmtime(time.time()))
30
31 if os.path.exists(time_dir):
32 logger.error("Path {} alreday exist".format(time_dir))
33 raise Logger_Exeception
34 else:
35 os.mkdir(time_dir)
36
37 return time_dir