Browse Source

finish setting up custom logger for demo mode

pull/18/head
Yair Fax 2 years ago
committed by Yair
parent
commit
01828ddf97
  1. 48
      actions/utils.py
  2. 2
      engine.py

48
actions/utils.py

@ -136,17 +136,61 @@ class CustomAdapter(logging.LoggerAdapter):
def __init__(self, logger, extras):
super().__init__(logger, extras)
self.ips = {}
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)
def process(self, msg, kwargs):
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):
"""

2
engine.py

@ -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):
"""

Loading…
Cancel
Save