diff --git a/common/helper.py b/common/helper.py index 498b805..31bc882 100755 --- a/common/helper.py +++ b/common/helper.py @@ -9,6 +9,7 @@ from datetime import time as _time import inspect from pathlib import Path +import re import threading from typing import Callable, List, Optional, Tuple import dateutil @@ -37,23 +38,28 @@ def validate_folders(config) -> Tuple[bool, str]: return False, f"No read/write access to {folder}" return True, "" + def localize_log_timestamps(loglines: List[str], config) -> None: if config.mercure.local_time == "UTC": return - try: local_tz: datetime.tzinfo = dateutil.tz.gettz(config.mercure.local_time) except: return + timestamp_pattern = re.compile(r'^(\S+)') + for i, line in enumerate(loglines): - split = line.split(" ") - timestamp = split[0] + match = timestamp_pattern.match(line) + if not match: + continue + + timestamp = match.group(1) try: parsed_dt = dateutil.parser.isoparse(timestamp) - dt_localtime:datetime.datetime = parsed_dt.astimezone(local_tz) - split[0] = dt_localtime.isoformat(timespec='seconds') - loglines[i] = " ".join(split) + dt_localtime: datetime.datetime = parsed_dt.astimezone(local_tz) + localized_timestamp = dt_localtime.isoformat(timespec='seconds') + loglines[i] = timestamp_pattern.sub(localized_timestamp, line) except: pass diff --git a/webgui.py b/webgui.py index c9f40d5..0caa69d 100755 --- a/webgui.py +++ b/webgui.py @@ -307,7 +307,7 @@ async def show_log(request) -> Response: f"sudo journalctl -n 1000 -u " f'{service_name} ' f"{start_date_cmd} {end_date_cmd} " - "-o short-iso" + "-o short-iso --no-hostname" ) return_code = -1 if run_result[0] is None else run_result[0] raw_logs = run_result[1]