]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/python3 | |
2 | ||
3 | import logging | |
4 | import os | |
5 | import time | |
6 | ||
7 | logger = logging.getLogger("nitsi.logger") | |
8 | ||
9 | class Logger_Exeception(BaseException): | |
10 | pass | |
11 | ||
12 | # This function should create the necessary folders | |
13 | # and touch the logging files | |
14 | def 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 |