fix: Disable timestamp in console handler -> provided by journalctl

This commit is contained in:
Piotr Dec 2026-05-08 03:53:14 +02:00
parent 976d739b18
commit 0445a4cef8
Signed by: stawros
GPG key ID: 74B18A3F0F1E99C0

View file

@ -32,19 +32,23 @@ class NamingCache:
class ApplicationFormatter(Formatter):
def __init__(self, handler_prefix: str = ''):
def __init__(self, handler_prefix: str = '', include_timestamp: bool = True):
super().__init__()
self._logger_names = NamingCache()
self._handler_prefix = handler_prefix
self._include_timestamp = include_timestamp
def format(self, record):
from datetime import datetime
timestamp = datetime.fromtimestamp(record.created).isoformat(sep=' ', timespec='milliseconds')
if self._include_timestamp:
timestamp = datetime.fromtimestamp(record.created).isoformat(sep=' ', timespec='milliseconds') + ' '
else:
timestamp = ''
level = record.levelname.replace('WARNING', 'WARN').rjust(5)
thread_name = record.threadName.replace(' (', '#').replace(')', '').rjust(16)[-16:] # TODO: NamingCache?
logger_name = self._logger_names[f"{self._handler_prefix}{record.name}"]
message = record.getMessage()
formatted = f"{timestamp} {level} [{thread_name}] {logger_name} : {message}"
formatted = f"{timestamp}{level} [{thread_name}] {logger_name} : {message}"
if record.exc_info:
formatted += "\n" + self.formatException(record.exc_info)
@ -62,7 +66,7 @@ class HandlerFactory:
def create(target: Target, handler_prefix: str = '', file_path: Path = None) -> List[Handler]:
def console_handler(prefix: str = ''):
handler = StreamHandler()
handler.setFormatter(ApplicationFormatter(prefix))
handler.setFormatter(ApplicationFormatter(prefix, include_timestamp=False))
handler.setLevel('INFO')
return handler