From d5eb120dcf2ca5b9a5810855b2456c4bc25ab531 Mon Sep 17 00:00:00 2001 From: "Julien M." Date: Mon, 5 Aug 2024 07:13:17 +0200 Subject: [PATCH] refactor(rss): use Qgis enums for log levels https://github.com/geotribu/qtribu/pull/188#discussion_r1703275923 --- qtribu/logic/news_feed/rss_reader.py | 16 ++++++++-------- qtribu/toolbelt/log_handler.py | 9 +++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/qtribu/logic/news_feed/rss_reader.py b/qtribu/logic/news_feed/rss_reader.py index 04e66ccd..f8261a9c 100644 --- a/qtribu/logic/news_feed/rss_reader.py +++ b/qtribu/logic/news_feed/rss_reader.py @@ -75,7 +75,7 @@ def process(self) -> None: f"The RSS feed is not available locally: {self.local_feed_filepath}. " "Features related to the RSS reader are disabled." ), - log_level=1, + log_level=Qgis.Critical, ) return @@ -84,7 +84,7 @@ def process(self) -> None: # check if a new item has been published since last check if not self.has_new_content: - self.log(message="No new item found in RSS feed.", log_level=4) + self.log(message="No new item found in RSS feed.", log_level=Qgis.NoLevel) return # notify if isinstance(self.latest_item, RssItem): @@ -94,7 +94,7 @@ def process(self) -> None: self.tr("New content published:"), latest_item.title, ), - log_level=3, + log_level=Qgis.Success, push=PlgOptionsManager().get_plg_settings().notify_push_info, duration=PlgOptionsManager().get_plg_settings().notify_push_duration, button=True, @@ -129,12 +129,12 @@ def download_feed(self) -> bool: self.log( message=f"The remote RSS feed ({self.plg_settings.rss_source}) has been " f"downloaded to {self.local_feed_filepath}", - log_level=0, + log_level=Qgis.Info, ) return True self.log( message=f"A fresh local RSS feed already exists: {self.local_feed_filepath}", - log_level=0, + log_level=Qgis.Info, ) return False @@ -155,7 +155,7 @@ def read_feed(self) -> list[RssItem]: message="Item ignored because unmatches the include pattern: {}".format( item.find("title").text ), - log_level=4, + log_level=Qgis.NoLevel, ) continue @@ -187,7 +187,7 @@ def read_feed(self) -> list[RssItem]: item_idx = items.index(item) err_msg = f"Feed item {item_idx} triggers an error. Trace: {err}" - self.log(message=err_msg, log_level=2) + self.log(message=err_msg, log_level=Qgis.Critical) # store feed items as attribute and return it self.FEED_ITEMS = feed_items @@ -263,7 +263,7 @@ def add_latest_item_to_news_feed(self) -> bool: if not plg_settings.integration_qgis_news_feed: self.log( message="The QGIS news feed integration is disabled. Abort!", - log_level=4, + log_level=Qgis.NoLevel, ) return False diff --git a/qtribu/toolbelt/log_handler.py b/qtribu/toolbelt/log_handler.py index cb765fe8..68331ef2 100644 --- a/qtribu/toolbelt/log_handler.py +++ b/qtribu/toolbelt/log_handler.py @@ -99,6 +99,15 @@ def log( button_more_text=detailed_error_message ) log(message="Plugin loaded - TEST", log_level=4, push=0) + + # also works using enums from Qgis: + # Qgis.Info, Qgis.Warning, Qgis.Critical, Qgis.Success, Qgis.NoLevel + from qgis.core import Qgis + log( + message="Something went wrong but it's not blocking", + log_level=Qgis.Warning + ) + """ # if not debug mode and not push, let's ignore INFO, SUCCESS and TEST debug_mode = plg_prefs_hdlr.PlgOptionsManager.get_plg_settings().debug_mode