From 5c3ae15bee3470bfa4e8480644de41c6d8b5ba1a Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 12 Apr 2023 20:02:26 +0300 Subject: [PATCH] Store device monitor logs in the project "logs" directory // Resolve #4596 --- HISTORY.rst | 1 + docs | 2 +- platformio/device/monitor/command.py | 32 +++++++++---------- platformio/device/monitor/filters/log2file.py | 8 +++-- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 90762705..d3218bba 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -17,6 +17,7 @@ PlatformIO Core 6 6.1.7 (2023-??-??) ~~~~~~~~~~~~~~~~~~ +* Implemented a new feature to store device monitor logs in the project's "logs" folder, making it easier to access and review device monitor logs for your projects (`issue #4596 `_) * Improved source file filtering functionality for the `Static Code Analysis `__ feature, making it easier to analyze only the code you need to * Added the ability to show a detailed library dependency tree only in `verbose mode `__, which can help you understand the relationship between libraries and troubleshoot issues more effectively (`issue #4517 `_) * Added the ability to run only the `device monitor `__ when using the `pio run -t monitor `__ command, saving you time and resources by skipping the build process diff --git a/docs b/docs index e3c5bb85..2c2cc23f 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit e3c5bb85973f41a48ad04e429531a7f9abb8d0ad +Subproject commit 2c2cc23f42e9c8268223e9b3b4b53739d88bb38c diff --git a/platformio/device/monitor/command.py b/platformio/device/monitor/command.py index 301de772..3cf13573 100644 --- a/platformio/device/monitor/command.py +++ b/platformio/device/monitor/command.py @@ -132,24 +132,24 @@ def device_monitor_cmd(**options): ensure_ready=True, ).find(initial_port=options["port"]) - if options["menu_char"] == options["exit_char"]: - raise exception.UserSideException( - "--exit-char can not be the same as --menu-char" - ) - - # check for unknown filters - if options["filters"]: - known_filters = set(get_available_filters()) - unknown_filters = set(options["filters"]) - known_filters - if unknown_filters: - options["filters"] = list(known_filters & set(options["filters"])) - click.secho( - ("Warning! Skipping unknown filters `%s`. Known filters are `%s`") - % (", ".join(unknown_filters), ", ".join(sorted(known_filters))), - fg="yellow", + if options["menu_char"] == options["exit_char"]: + raise exception.UserSideException( + "--exit-char can not be the same as --menu-char" ) - start_terminal(options) + # check for unknown filters + if options["filters"]: + known_filters = set(get_available_filters()) + unknown_filters = set(options["filters"]) - known_filters + if unknown_filters: + options["filters"] = list(known_filters & set(options["filters"])) + click.secho( + ("Warning! Skipping unknown filters `%s`. Known filters are `%s`") + % (", ".join(unknown_filters), ", ".join(sorted(known_filters))), + fg="yellow", + ) + + start_terminal(options) def get_project_options(environment=None): diff --git a/platformio/device/monitor/filters/log2file.py b/platformio/device/monitor/filters/log2file.py index bf97b551..8e00d297 100644 --- a/platformio/device/monitor/filters/log2file.py +++ b/platformio/device/monitor/filters/log2file.py @@ -13,7 +13,7 @@ # limitations under the License. import io -import os.path +import os from datetime import datetime from platformio.device.monitor.filters.base import DeviceMonitorFilterBase @@ -27,8 +27,10 @@ class LogToFile(DeviceMonitorFilterBase): self._log_fp = None def __call__(self): - log_file_name = "platformio-device-monitor-%s.log" % datetime.now().strftime( - "%y%m%d-%H%M%S" + if not os.path.isdir("logs"): + os.makedirs("logs") + log_file_name = os.path.join( + "logs", "device-monitor-%s.log" % datetime.now().strftime("%y%m%d-%H%M%S") ) print("--- Logging an output to %s" % os.path.abspath(log_file_name)) # pylint: disable=consider-using-with