Skip to content

Commit

Permalink
refactor(rss): use Qgis enums for log levels
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Aug 5, 2024
1 parent d7721ad commit d5eb120
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
16 changes: 8 additions & 8 deletions qtribu/logic/news_feed/rss_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand All @@ -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,
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions qtribu/toolbelt/log_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d5eb120

Please sign in to comment.