don't include date in logging when running via systemd

This commit is contained in:
Izalia Mae 2024-03-21 22:50:22 -04:00
parent a6f1738b73
commit 491f19a9cb

View file

@ -63,10 +63,10 @@ def set_level(level: LogLevel | str) -> None:
def verbose(message: str, *args: Any, **kwargs: Any) -> None: def verbose(message: str, *args: Any, **kwargs: Any) -> None:
if not logging.root.isEnabledFor(LogLevel['VERBOSE']): if not logging.root.isEnabledFor(LogLevel.VERBOSE):
return return
logging.log(LogLevel['VERBOSE'], message, *args, **kwargs) logging.log(LogLevel.VERBOSE, message, *args, **kwargs)
debug: Callable = logging.debug debug: Callable = logging.debug
@ -76,8 +76,6 @@ error: Callable = logging.error
critical: Callable = logging.critical critical: Callable = logging.critical
env_log_level: Path | str | None = os.environ.get('LOG_LEVEL', 'INFO').upper()
try: try:
env_log_file: Path | None = Path(os.environ['LOG_FILE']).expanduser().resolve() env_log_file: Path | None = Path(os.environ['LOG_FILE']).expanduser().resolve()
@ -89,10 +87,16 @@ handlers: list[Any] = [logging.StreamHandler()]
if env_log_file: if env_log_file:
handlers.append(logging.FileHandler(env_log_file)) handlers.append(logging.FileHandler(env_log_file))
logging.addLevelName(LogLevel['VERBOSE'], 'VERBOSE') if os.environ.get('INVOCATION_ID'):
logging_format = '%(levelname)s: %(message)s'
else:
logging_format = '[%(asctime)s] %(levelname)s: %(message)s'
logging.addLevelName(LogLevel.VERBOSE, 'VERBOSE')
logging.basicConfig( logging.basicConfig(
level = LogLevel.INFO, level = LogLevel.INFO,
format = '[%(asctime)s] %(levelname)s: %(message)s', format = logging_format,
datefmt = '%Y-%m-%d %H:%M:%S', datefmt = '%Y-%m-%d %H:%M:%S',
handlers = handlers handlers = handlers
) )