Add separate Logger
instance on YoutubeDL
#7517
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
IMPORTANT: PRs without the template will be CLOSED
Description of your pull request and other information
This PR adds a logging interface at
YoutubeDL.logger
, resembling #5680. While the class and interface is not final, its methods can already be used.It also redirects
warnings.warn
messages to the logger.Template
Before submitting a pull request make sure you have:
In order to be accepted and merged into yt-dlp each piece of code must be in public domain or released under Unlicense. Check all of the following options that apply:
What is the purpose of your pull request?
Copilot Summary
馃 Generated by Copilot at e889cb8
Summary
馃摑馃帹馃殌
This pull request introduces a new
_Logger
class that handles all the output and warning functionality of theYoutubeDL
class, and refactors the existing code to use it. It also adds some helper functions to redirect thewarnings
module and set the return code based on the error messages. The changes affect theyt_dlp/YoutubeDL.py
,yt_dlp/output/helper.py
, andyt_dlp/output/logger.py
files.Walkthrough
YoutubeDL
by using a_Logger
instance from theoutput.logger
module (link, link, link, link, link)redirect_warnings
and_wrap_download_retcode
functions to theoutput.helper
module, which are used to redirect the messages from thewarnings
module to the_Logger
instance, and to set the return code of theYoutubeDL
instance based on the error messages, respectively (link)_Logger
class to theoutput.logger
module, which encapsulates the logic for handling the output files, color policies, VT mode, bidirectional workaround, and logging and warning messages. It also defines the_Styles
namespace, which contains the color codes for different types of messages (link)tb
andis_error
arguments of thetrouble
method of theYoutubeDL
class keyword-only, to avoid confusion and errors when calling the method with positional arguments (link)YoutubeDL.py
(link, link, link, link, link, link)