mirror of
https://github.com/Kkevsterrr/geneva
synced 2025-01-02 23:15:11 +01:00
add docstring
This commit is contained in:
parent
0abac72ddb
commit
b5313e929e
@ -129,7 +129,7 @@ def get_logger(basepath, log_dir, logger_name, log_name, environment_id, log_lev
|
||||
|
||||
class CustomAdapter(logging.LoggerAdapter):
|
||||
"""
|
||||
Used for demo mode, to change sensitive IP addresses where necessary
|
||||
Used for demo mode, to change sensitive IP addresses where necessary. Can be used (mostly) like a regular logger.
|
||||
"""
|
||||
regex = re.compile(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")
|
||||
|
||||
@ -139,37 +139,59 @@ class CustomAdapter(logging.LoggerAdapter):
|
||||
self.ips = {}
|
||||
|
||||
def debug(self, msg, *args, **kwargs):
|
||||
"""
|
||||
Print a debug message, uses logger.debug.
|
||||
"""
|
||||
msg, args, kwargs = self.process(msg, args, kwargs)
|
||||
|
||||
self.logger.debug(msg, *args, **kwargs)
|
||||
|
||||
def info(self, msg, *args, **kwargs):
|
||||
"""
|
||||
Print an info message, uses logger.info.
|
||||
"""
|
||||
msg, args, kwargs = self.process(msg, args, kwargs)
|
||||
|
||||
self.logger.info(msg, *args, **kwargs)
|
||||
|
||||
def warning(self, msg, *args, **kwargs):
|
||||
"""
|
||||
Print a warning message, uses logger.warning.
|
||||
"""
|
||||
msg, args, kwargs = self.process(msg, args, kwargs)
|
||||
|
||||
self.logger.warning(msg, *args, **kwargs)
|
||||
|
||||
def error(self, msg, *args, **kwargs):
|
||||
"""
|
||||
Print an error message, uses logger.error.
|
||||
"""
|
||||
msg, args, kwargs = self.process(msg, args, kwargs)
|
||||
|
||||
self.logger.error(msg, *args, **kwargs)
|
||||
|
||||
def critical(self, msg, *args, **kwargs):
|
||||
"""
|
||||
Print a critical message, uses logger.critical.
|
||||
"""
|
||||
msg, args, kwargs = self.process(msg, args, kwargs)
|
||||
|
||||
self.logger.critical(msg, *args, **kwargs)
|
||||
|
||||
def get_ip(self, ip):
|
||||
"""
|
||||
Lookup the assigned random IP for a given real IP.
|
||||
If no random IP exists, a new one is created and a message is logged indicating it.
|
||||
"""
|
||||
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):
|
||||
"""
|
||||
Modify the log message to replace any instance of an IP in msg or args with its assigned random IP.
|
||||
"""
|
||||
new_args = []
|
||||
for arg in args:
|
||||
if type(arg) == str:
|
||||
@ -178,7 +200,6 @@ class CustomAdapter(logging.LoggerAdapter):
|
||||
|
||||
arg = arg.replace(ip, self.ips[ip])
|
||||
|
||||
|
||||
new_args.append(arg)
|
||||
|
||||
for ip in self.regex.findall(msg):
|
||||
|
Loading…
Reference in New Issue
Block a user