-
Notifications
You must be signed in to change notification settings - Fork 6
/
logger.py
39 lines (31 loc) · 1.17 KB
/
logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import logging
import os
class Logger:
def __init__(self):
self.create_log()
def create_log(self):
"""
For debugging and informational purposes.
"""
self.ensure_log_folder_exists()
log = logging.getLogger('minxss_beacon_decoder_debug')
if not self.logger_exists(log):
handler = logging.FileHandler(self.create_log_filename())
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
log.addHandler(handler)
log.setLevel(logging.DEBUG)
return log
@staticmethod
def logger_exists(log):
if len(log.handlers) > 0:
return True
else:
return False
@staticmethod
def ensure_log_folder_exists():
if not os.path.exists(os.path.join(os.path.expanduser("~"), "MinXSS_Beacon_Decoder", "log")):
os.makedirs(os.path.join(os.path.expanduser("~"), "MinXSS_Beacon_Decoder", "log"))
@staticmethod
def create_log_filename():
return os.path.join(os.path.expanduser("~"), "MinXSS_Beacon_Decoder", "log", "minxss_beacon_decoder_debug.log")