fix: Disable timestamp in console handler -> provided by journalctl
This commit is contained in:
parent
976d739b18
commit
0445a4cef8
1 changed files with 8 additions and 4 deletions
|
|
@ -32,14 +32,18 @@ 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}"]
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue