class TestFormatter(logging.Formatter):
- def __init__(self, start_time=None, name=None):
+ def __init__(self, start_time=None, name=None, longest_machine_name=10):
super().__init__(fmt="[%(asctime)s] %(message)s")
logger.debug("Initiating TestFormatter for")
if start_time == None:
else:
self.name = name
+ self.longest_machine_name = longest_machine_name
+
def converter(self, recordtime):
# This returns a timestamp relatively to the time when we started
return time.gmtime(recordtime)
def format(self, record):
- return "[{}][{}] {}".format(self.formatTime(record), self.name, record.getMessage())
+ return "[{}][{:^{align}}] {}".format(self.formatTime(record),
+ self.name,
+ record.getMessage(),
+ align=self.longest_machine_name)
def formatTime(self, record, datefmt=None):
ct = self.converter(record.created)
t = time.strftime("%H:%M:%S", ct)
s = "{}.{:03d}".format(t, round(record.msecs,None))
return s
+
+
+class Log_Formatter(logging.Formatter):
+ def __init__(self):
+ super().__init__(fmt="[%(asctime)s] [%(levelname)s] %(message)s")
+ logger.debug("Initiating Log_Formatter")
+
+ def format(self, record):
+ # We use 8 to align the levelname, because CRITICAL ist the longest name and has 8 chars
+ return "[{}][{:^}][{:^8}] {}".format(self.formatTime(record),
+ record.name,
+ record.levelname,
+ record.getMessage())
+
+ def formatTime(self, record, datefmt=None):
+ t = time.strftime("%H:%M:%S", time.gmtime(record.created))
+ s = "{}.{:03d}".format(t, round(record.msecs,None))
+ return s
\ No newline at end of file