From 36fb12317f48bcb0f268f467acd8320fd97df52a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Sat, 25 Oct 2025 15:24:48 +0200 Subject: [PATCH] mlog: add a new log file with the setup logs Add meson-setup.txt to keep the configure log out of the debug logs. --- docs/markdown/snippets/meson-configure-log.md | 6 ++++++ mesonbuild/mlog.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 docs/markdown/snippets/meson-configure-log.md diff --git a/docs/markdown/snippets/meson-configure-log.md b/docs/markdown/snippets/meson-configure-log.md new file mode 100644 index 000000000000..8a1a8765439a --- /dev/null +++ b/docs/markdown/snippets/meson-configure-log.md @@ -0,0 +1,6 @@ +## Add a configure log in meson-logs + +Add a second log file `meson-setup.txt` which contains the configure logs +displayed on stdout during the meson `setup` stage. +It allows user to navigate through the setup logs without searching in the terminal +or the extensive informations of `meson-log.txt`. \ No newline at end of file diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py index 86ac0d102fc0..e1d998a5d340 100644 --- a/mesonbuild/mlog.py +++ b/mesonbuild/mlog.py @@ -67,6 +67,7 @@ class _Logger: log_depth: T.List[str] = field(default_factory=list) log_to_stderr: bool = False log_file: T.Optional[T.TextIO] = None + slog_file: T.Optional[T.TextIO] = None log_timestamp_start: T.Optional[float] = None log_fatal_warnings = False log_disable_stdout = False @@ -76,6 +77,7 @@ class _Logger: log_pager: T.Optional['subprocess.Popen'] = None _LOG_FNAME: T.ClassVar[str] = 'meson-log.txt' + _SLOG_FNAME: T.ClassVar[str] = 'meson-setup.txt' @contextmanager def no_logging(self) -> T.Iterator[None]: @@ -110,6 +112,12 @@ def shutdown(self) -> T.Optional[str]: self.log_file = None exception_around_goer.close() return path + if self.slog_file is not None: + path = self.slog_file.name + exception_around_goer = self.slog_file + self.slog_file = None + exception_around_goer.close() + return path self.stop_pager() return None @@ -164,6 +172,7 @@ def stop_pager(self) -> None: def initialize(self, logdir: str, fatal_warnings: bool = False) -> None: self.log_dir = logdir self.log_file = open(os.path.join(logdir, self._LOG_FNAME), 'w', encoding='utf-8') + self.slog_file = open(os.path.join(logdir, self._SLOG_FNAME), 'w', encoding='utf-8') self.log_fatal_warnings = fatal_warnings def process_markup(self, args: T.Sequence[TV_Loggable], keep: bool, display_timestamp: bool = True) -> T.List[str]: @@ -224,6 +233,9 @@ def _log(self, *args: TV_Loggable, is_error: bool = False, if self.log_file is not None: print(*arr, file=self.log_file, sep=sep, end=end) self.log_file.flush() + if self.slog_file is not None: + print(*arr, file=self.slog_file, sep=sep, end=end) + self.slog_file.flush() if self.colorize_console(): arr = process_markup(args, True, display_timestamp) if not self.log_errors_only or is_error: