Adjust: [logging] header/content debug log indended by space to be skipped by logwatch

This commit is contained in:
Peter Bieringer
2025-12-10 18:01:14 +01:00
parent bac608a37a
commit 183e556144
5 changed files with 26 additions and 12 deletions

View File

@@ -21,6 +21,7 @@ import datetime
import os
import ssl
import sys
import textwrap
from importlib import import_module, metadata
from typing import Callable, Sequence, Tuple, Type, TypeVar, Union
@@ -291,3 +292,16 @@ def format_ut(unixtime: int) -> str:
dt = datetime.datetime.fromtimestamp(unixtime, datetime.UTC)
r = str(unixtime) + "(" + dt.strftime('%Y-%m-%dT%H:%M:%SZ') + ")"
return r
def limit_str(content: str, limit: int) -> str:
length = len(content)
if limit > 0 and length >= limit:
return content[:limit] + ("...(shortened because original length %d > limit %d)" % (length, limit))
else:
return content
def textwrap_str(content: str, limit: int = 2000) -> str:
# TODO: add support for config option and prefix
return textwrap.indent(limit_str(content, limit), " ", lambda line: True)