logger used in codebase
This commit is contained in:
parent
ef8f46ac30
commit
0a586ee95f
6 changed files with 21 additions and 22 deletions
|
|
@ -17,10 +17,13 @@ from ytdl_sub.config.preset_options import Overrides
|
|||
from ytdl_sub.downloaders.downloader import Downloader
|
||||
from ytdl_sub.downloaders.downloader import DownloaderValidator
|
||||
from ytdl_sub.entries.youtube import YoutubeVideo
|
||||
from ytdl_sub.utils.logger import Logger
|
||||
from ytdl_sub.validators.date_range_validator import DateRangeValidator
|
||||
from ytdl_sub.validators.string_formatter_validators import OverridesStringFormatterValidator
|
||||
from ytdl_sub.validators.validators import StringValidator
|
||||
|
||||
logger = Logger.get()
|
||||
|
||||
###############################################################################
|
||||
# Abstract Youtube downloader + options
|
||||
|
||||
|
|
@ -223,7 +226,7 @@ class YoutubeChannelDownloader(YoutubeDownloader[YoutubeChannelDownloaderOptions
|
|||
break
|
||||
|
||||
if not thumbnail_url:
|
||||
# TODO: add logger with warn here
|
||||
logger.warning("Could not find a thumbnail for %s", entry_dict.get("id"))
|
||||
return
|
||||
|
||||
with urlopen(thumbnail_url) as file:
|
||||
|
|
|
|||
|
|
@ -1,18 +1,15 @@
|
|||
import argparse
|
||||
import sys
|
||||
import traceback
|
||||
from typing import List
|
||||
|
||||
from ytdl_sub.cli.download_args_parser import DownloadArgsParser
|
||||
from ytdl_sub.cli.main_args_parser import parser
|
||||
from ytdl_sub.config.config_file import ConfigFile
|
||||
from ytdl_sub.config.subscription import SubscriptionValidator
|
||||
from ytdl_sub.logging import YtdlSubLogger
|
||||
from ytdl_sub.utils.exceptions import ValidationException
|
||||
from ytdl_sub.utils.logger import Logger
|
||||
|
||||
DEBUGGER_MODE = True
|
||||
|
||||
logger = YtdlSubLogger.logger()
|
||||
logger = Logger.get()
|
||||
|
||||
|
||||
def _download_subscriptions_from_yaml_files(config: ConfigFile, args: argparse.Namespace) -> None:
|
||||
|
|
@ -72,15 +69,10 @@ if __name__ == "__main__":
|
|||
try:
|
||||
main()
|
||||
except ValidationException as validation_exception:
|
||||
if DEBUGGER_MODE:
|
||||
raise
|
||||
logger.error(validation_exception)
|
||||
sys.exit(1)
|
||||
except Exception as exc: # pylint: disable=broad-except
|
||||
if DEBUGGER_MODE:
|
||||
raise
|
||||
print(traceback.format_exc())
|
||||
print(
|
||||
logger.exception(
|
||||
"A fatal error occurred. Please copy and paste the stacktrace above and make a Github "
|
||||
"issue at https://github.com/jmbannon/ytdl-subscribe/issues with your config and "
|
||||
"command/subscription yaml file to reproduce. Thanks for trying ytdl-subscribe!"
|
||||
|
|
|
|||
|
|
@ -31,10 +31,11 @@ class MusicTagsPlugin(Plugin[MusicTagsOptions]):
|
|||
audio_file = mediafile.MediaFile(entry.get_download_file_path())
|
||||
for tag, tag_formatter in self.plugin_options.tags.dict.items():
|
||||
if tag not in audio_file.fields():
|
||||
# TODO: Add proper logger and warn here
|
||||
print(
|
||||
f"[ytld-sub: WARN] tag {tag} is not supported for {entry.ext} files. Supported "
|
||||
f"tags: {', '.join(audio_file.sorted_fields())}"
|
||||
self._logger.warning(
|
||||
"tag '%s' is not supported for %s files. Supported tags: %s",
|
||||
tag,
|
||||
entry.ext,
|
||||
", ".join(audio_file.sorted_fields()),
|
||||
)
|
||||
|
||||
tag_value = self.overrides.apply_formatter(formatter=tag_formatter, entry=entry)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from typing import final
|
|||
|
||||
from ytdl_sub.config.preset_options import Overrides
|
||||
from ytdl_sub.entries.entry import Entry
|
||||
from ytdl_sub.utils.logger import Logger
|
||||
from ytdl_sub.validators.strict_dict_validator import StrictDictValidator
|
||||
from ytdl_sub.ytdl_additions.enhanced_download_archive import EnhancedDownloadArchive
|
||||
|
||||
|
|
@ -38,6 +39,8 @@ class Plugin(Generic[PluginOptionsT], ABC):
|
|||
self.output_directory = output_directory
|
||||
self.overrides = overrides
|
||||
self.__enhanced_download_archive = enhanced_download_archive
|
||||
# TODO pass yaml snake case name in the class somewhere, and use it for the logger
|
||||
self._logger = Logger.get(self.__class__.__name__)
|
||||
|
||||
@final
|
||||
def archive_entry_file_name(self, entry: Entry, relative_file_path: str) -> None:
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import sys
|
|||
from typing import Optional
|
||||
|
||||
|
||||
class YtdlSubLogger:
|
||||
class Logger:
|
||||
@classmethod
|
||||
def _get_formatter(cls) -> logging.Formatter:
|
||||
"""
|
||||
|
|
@ -26,7 +26,7 @@ class YtdlSubLogger:
|
|||
return handler
|
||||
|
||||
@classmethod
|
||||
def logger(cls, name: Optional[str] = None) -> logging.Logger:
|
||||
def get(cls, name: Optional[str] = None) -> logging.Logger:
|
||||
"""
|
||||
Parameters
|
||||
----------
|
||||
|
|
@ -13,7 +13,7 @@ from typing import Set
|
|||
from yt_dlp import DateRange
|
||||
|
||||
from ytdl_sub.entries.entry import Entry
|
||||
from ytdl_sub.logging import YtdlSubLogger
|
||||
from ytdl_sub.utils.logger import Logger
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
@ -337,7 +337,7 @@ class EnhancedDownloadArchive:
|
|||
self._download_archive: Optional[DownloadArchive] = None
|
||||
self._download_mapping: Optional[DownloadMappings] = None
|
||||
|
||||
self.logger = YtdlSubLogger.logger(name=subscription_name)
|
||||
self._logger = Logger.get(name=subscription_name)
|
||||
|
||||
@property
|
||||
def archive_file_name(self) -> str:
|
||||
|
|
@ -463,10 +463,10 @@ class EnhancedDownloadArchive:
|
|||
)
|
||||
|
||||
for uid, mapping in stale_mappings.items():
|
||||
self.logger.info("[%s] Removing the following stale file(s):", uid)
|
||||
self._logger.info("[%s] Removing the following stale file(s):", uid)
|
||||
for file_name in mapping.file_names:
|
||||
file_path = Path(self.output_directory) / Path(file_name)
|
||||
self.logger.info(" - %s", file_path)
|
||||
self._logger.info(" - %s", file_path)
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue