This commit is contained in:
WhatDidYouExpect 2025-07-21 21:12:31 +02:00
parent 3c71e9f54e
commit 221f2370e4
5 changed files with 19 additions and 133 deletions

View file

@ -1,4 +1,5 @@
import logging
import re
from modules.globalvars import *
class GooberFormatter(logging.Formatter):
@ -16,10 +17,14 @@ class GooberFormatter(logging.Formatter):
}
def format(self, record: logging.LogRecord):
ansiescape = re.compile(r'\x1B[@-_][0-?]*[ -/]*[@-~]')
if self.colors:
log_fmt = self.FORMATS.get(record.levelno) # Add colors
else:
log_fmt = self._format # Just use the default format
formatter = logging.Formatter(log_fmt, datefmt="%m/%d/%y %H:%M:%S")
return formatter.format(record)
formatted = formatter.format(record)
if not self.colors:
formatted = ansiescape.sub('', formatted)
return formatted