"""Private, replayable entity permutations and defensive log rendering.""" import hashlib import random import re PREFIX = {"service": "SVC", "instance": "INST", "host": "HOST"} SAFE_WORDS = frozenset(""" a an and at by for from in of on or the to with after before aborted access address already application authentication available bad broken cancelled client closed code connection denied disconnected dropped duplicate empty end error exceeded exception failed failure fatal found handshake health internal invalid io limit lost memory missing not out overloaded packet permission pool queue rate refused request reset resource response retry server service slow socket status stream successful unavailable unexpected unknown warn warning crash crashed deadline eof exhausted oom timeout timed receive read send write operation parse protocol upstream downstream database container process thread allocation overflow underflow restart backoff """.split()) TOKEN = re.compile(r"[\w.-]+|[^\w\s]", re.UNICODE) def entity_pattern(values): names = sorted({name for name in values if name}, key=lambda name: (-len(name), name)) if not names: return re.compile(r"(?!)") choices = "|".join(map(re.escape, names)) return re.compile(r"(?"}: if not shown or shown[-1] != "": shown.append("") for match in self.__pattern.finditer(message): safe_words(message[previous:match.start()]) shown.append(self.__aliases[match.group().lower()]) previous = match.end() safe_words(message[previous:]) while shown and sum(len(word) + 1 for word in shown) - 1 > max_chars: shown.pop() return " ".join(shown)