home · contact · privacy
Log date changes, sort log files into dates.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 24 Sep 2025 06:56:15 +0000 (08:56 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 24 Sep 2025 06:56:15 +0000 (08:56 +0200)
ircplom/client_tui.py
ircplom/tui_base.py

index 26ea085da1a781820a3fa821269bb31adcacd82e..185964f7da0b4e47ce8e06499f4a45ca8885fa65 100644 (file)
@@ -46,10 +46,10 @@ class _ClientWindow(Window, ClientQueueMixin):
 
     def log(self, msg: str) -> None:
         super().log(msg)
-        if not exists(_PATH_LOGS):
-            makedirs(_PATH_LOGS)
-        with open(f'{_PATH_LOGS}/{self._title}.txt', 'a', encoding='utf8'
-                  ) as f:
+        ldir = f'{_PATH_LOGS}/{self._title}'
+        if not exists(ldir):
+            makedirs(ldir)
+        with open(f'{ldir}/{self._last_today}.txt', 'a', encoding='utf8') as f:
             f.write(msg + '\n')
 
     def _send_msg(self, verb: str, params: tuple[str, ...]) -> None:
index f6a3f9697fb0b896ba2b539026610070b65de6f9..73115a1ba492de1d0d33ef8c80af3481ba53bb0a 100644 (file)
@@ -322,6 +322,7 @@ class Window:
     _drawable = False
     prompt: PromptWidget
     _title = ':start'
+    _last_today = ''
 
     def __init__(self, idx: int, term: 'Terminal', **kwargs) -> None:
         super().__init__(**kwargs)
@@ -333,6 +334,12 @@ class Window:
         if hasattr(self._term, 'size'):
             self.set_geometry()
 
+    def ensure_date(self, today: str) -> None:
+        'Log date of today if it has not been logged yet.'
+        if today != self._last_today:
+            self._last_today = today
+            self.log(today)
+
     def log(self, msg: str) -> None:
         'Append msg to .history.'
         self.history.append(msg)
@@ -449,10 +456,13 @@ class BaseTui(QueueMixin):
         prefix = kwargs.get('prefix', _LOG_PREFIX_DEFAULT)
         if kwargs.get('alert', False):
             prefix = _LOG_PREFIX_ALERT + prefix
-        msg = f'{str(datetime.now())[11:19]} {prefix} {msg}'
+        now = str(datetime.now())
+        today, time = now[:10], now[11:19]
+        msg = f'{time} {prefix} {msg}'
         affected_win_indices = []
         for win in self._log_target_wins(**kwargs):
             affected_win_indices += [win.idx]
+            win.ensure_date(today)
             win.log(msg)
             if win != self.window:
                 self._status_line.taint()