Improve logging
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
@ -9,11 +10,13 @@ from markdownify import markdownify
|
||||
from reader import Entry, Feed, Reader, TagNotFoundError
|
||||
|
||||
from discord_rss_bot.is_url_valid import is_url_valid
|
||||
from discord_rss_bot.settings import get_reader, logger
|
||||
from discord_rss_bot.settings import get_reader
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from reader.types import JSONType
|
||||
|
||||
logger: logging.Logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class CustomEmbed:
|
||||
@ -132,7 +135,7 @@ def get_first_image(summary: str | None, content: str | None) -> str:
|
||||
if content and (images := BeautifulSoup(content, features="lxml").find_all("img")):
|
||||
for image in images:
|
||||
if not is_url_valid(image.attrs["src"]):
|
||||
logger.warning(f"Invalid URL: {image.attrs['src']}")
|
||||
logger.warning("Invalid URL: %s", image.attrs["src"])
|
||||
continue
|
||||
|
||||
# Genshins first image is a divider, so we ignore it.
|
||||
@ -141,7 +144,7 @@ def get_first_image(summary: str | None, content: str | None) -> str:
|
||||
if summary and (images := BeautifulSoup(summary, features="lxml").find_all("img")):
|
||||
for image in images:
|
||||
if not is_url_valid(image.attrs["src"]):
|
||||
logger.warning(f"Invalid URL: {image.attrs['src']}")
|
||||
logger.warning("Invalid URL: %s", image.attrs["src"])
|
||||
continue
|
||||
|
||||
# Genshins first image is a divider, so we ignore it.
|
||||
@ -220,7 +223,6 @@ def replace_tags_in_embed(feed: Feed, entry: Entry) -> CustomEmbed:
|
||||
{"{{entry_updated}}": entry_updated or ""},
|
||||
{"{{image_1}}": first_image or ""},
|
||||
]
|
||||
|
||||
for replacement in list_of_replacements:
|
||||
for template, replace_with in replacement.items():
|
||||
embed.title = try_to_replace(embed.title, template, replace_with)
|
||||
|
@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
import pprint
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
@ -12,13 +13,15 @@ from discord_rss_bot import custom_message
|
||||
from discord_rss_bot.filter.blacklist import should_be_skipped
|
||||
from discord_rss_bot.filter.whitelist import has_white_tags, should_be_sent
|
||||
from discord_rss_bot.is_url_valid import is_url_valid
|
||||
from discord_rss_bot.settings import default_custom_message, get_reader, logger
|
||||
from discord_rss_bot.settings import default_custom_message, get_reader
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Iterable
|
||||
|
||||
from requests import Response
|
||||
|
||||
logger: logging.Logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def send_entry_to_discord(entry: Entry, custom_reader: Reader | None = None) -> str | None:
|
||||
"""Send a single entry to Discord.
|
||||
@ -186,11 +189,11 @@ def send_to_discord(custom_reader: Reader | None = None, feed: Feed | None = Non
|
||||
# Set the webhook to read, so we don't send it again.
|
||||
try:
|
||||
reader.set_entry_read(entry, True)
|
||||
except EntryNotFoundError as e:
|
||||
logger.error("Error setting entry to read: %s", e)
|
||||
except EntryNotFoundError:
|
||||
logger.exception("Error setting entry to read: %s", entry.id)
|
||||
continue
|
||||
except StorageError as e:
|
||||
logger.error("Error setting entry to read: %s", e)
|
||||
except StorageError:
|
||||
logger.exception("Error setting entry to read: %s", entry.id)
|
||||
continue
|
||||
|
||||
# Get the webhook URL for the entry. If it is None, we will continue to the next entry.
|
||||
|
@ -52,11 +52,13 @@ LOGGING_CONFIG = {
|
||||
"version": 1,
|
||||
"disable_existing_loggers": True,
|
||||
"formatters": {
|
||||
"standard": {"format": "%(asctime)s [%(levelname)s] %(name)s: %(message)s"},
|
||||
"standard": {
|
||||
"format": "%(asctime)s [%(processName)s: %(process)d] [%(threadName)s: %(thread)d] [%(levelname)s] %(name)s: %(message)s", # noqa: E501
|
||||
},
|
||||
},
|
||||
"handlers": {
|
||||
"default": {
|
||||
"level": "INFO",
|
||||
"level": "DEBUG",
|
||||
"formatter": "standard",
|
||||
"class": "logging.StreamHandler",
|
||||
"stream": "ext://sys.stdout", # Default is stderr
|
||||
@ -64,7 +66,7 @@ LOGGING_CONFIG = {
|
||||
},
|
||||
"loggers": {
|
||||
"": { # root logger
|
||||
"level": "INFO",
|
||||
"level": "DEBUG",
|
||||
"handlers": ["default"],
|
||||
"propagate": False,
|
||||
},
|
||||
|
@ -1,7 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import sys
|
||||
import typing
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
@ -15,16 +13,6 @@ if typing.TYPE_CHECKING:
|
||||
data_dir: str = user_data_dir(appname="discord_rss_bot", appauthor="TheLovinator", roaming=True, ensure_exists=True)
|
||||
|
||||
|
||||
logger: logging.Logger = logging.getLogger("discord_rss_bot")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
stream_handler = logging.StreamHandler(sys.stdout)
|
||||
log_formatter = logging.Formatter(
|
||||
"%(asctime)s [%(processName)s: %(process)d] [%(threadName)s: %(thread)d] [%(levelname)s] %(name)s: %(message)s",
|
||||
)
|
||||
stream_handler.setFormatter(log_formatter)
|
||||
logger.addHandler(stream_handler)
|
||||
|
||||
|
||||
# TODO(TheLovinator): Add default things to the database and make the edible.
|
||||
default_custom_message: JSONType | str = "{{entry_title}}\n{{entry_link}}"
|
||||
default_custom_embed: dict[str, str] = {
|
||||
|
@ -218,7 +218,6 @@
|
||||
Something went wrong, there was no entry found. If this feed has entries and you still see this message, please contact the developer.
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<label for="title" class="col-sm-6 col-form-label">Title</label>
|
||||
<input name="title"
|
||||
type="text"
|
||||
|
Reference in New Issue
Block a user