finish setting up custom logger for demo mode

This commit is contained in:
Yair Fax 2020-07-01 18:34:49 +00:00 committed by Yair
parent 216e5636c4
commit 01828ddf97
2 changed files with 47 additions and 3 deletions

View File

@ -137,16 +137,60 @@ class CustomAdapter(logging.LoggerAdapter):
super().__init__(logger, extras)
self.ips = {}
def process(self, msg, kwargs):
def debug(self, msg, *args, **kwargs):
msg, args, kwargs = self.process(msg, args, kwargs)
self.logger.debug(msg, *args, **kwargs)
def info(self, msg, *args, **kwargs):
msg, args, kwargs = self.process(msg, args, kwargs)
self.logger.info(msg, *args, **kwargs)
def warning(self, msg, *args, **kwargs):
msg, args, kwargs = self.process(msg, args, kwargs)
self.logger.warning(msg, *args, **kwargs)
def error(self, msg, *args, **kwargs):
msg, args, kwargs = self.process(msg, args, kwargs)
self.logger.error(msg, *args, **kwargs)
def critical(self, msg, *args, **kwargs):
msg, args, kwargs = self.process(msg, args, kwargs)
self.logger.critical(msg, *args, **kwargs)
def get_ip(self, ip):
if ip not in self.ips:
random_ip = socket.inet_ntoa(struct.pack('>I', random.randint(1, 0xffffffff)))
self.logger.info("Registering new random IP: %s" % random_ip)
self.ips[ip] = random_ip
def process(self, msg, args, kwargs):
new_args = []
for arg in args:
if type(arg) == str:
for ip in self.regex.findall(arg):
new_ip = self.get_ip(ip)
arg = arg.replace(ip, self.ips[ip])
new_args.append(arg)
for ip in self.regex.findall(msg):
if ip not in self.ips:
random_ip = socket.inet_ntoa(struct.pack('>I', random.randint(1, 0xffffffff)))
self.logger.debug("Registering new random IP: %s" % random_ip)
self.ips[ip] = random_ip
new_ip = self.get_ip(ip)
msg = msg.replace(ip, self.ips[ip])
return msg, kwargs
return msg, tuple(new_args), kwargs
def close_logger(logger):
"""

View File

@ -193,7 +193,7 @@ class Engine():
while (not self.in_nfqueue_started or not self.out_nfqueue_started) and i < maxwait:
time.sleep(0.1)
i += 1
self.logger.debug(("NFQueue Initialized after %d", int(i)))
self.logger.debug("NFQueue Initialized after %d", int(i))
def shutdown_nfqueue(self):
"""