Skip to content

Bulk asynchronous downloader for multiple file hosts

refactor: remove support for int log levels (#1960)

NTFSvolume9ecbe7f0156d
diff --git a/cyberdrop_dl/config/_global.py b/cyberdrop_dl/config/_global.py
index 5613e51ef..a07644b0c 100644
--- a/cyberdrop_dl/config/_global.py
+++ b/cyberdrop_dl/config/_global.py
@@ -6,6 +6,7 @@ import aiohttp
from cyclopts import Parameter
from pydantic import (
ByteSize,
+ Field,
NonNegativeFloat,
PositiveFloat,
PositiveInt,
@@ -115,7 +116,7 @@ class GenericCrawlerInstances(SettingsGroup):
@Parameter(name="*")
class GlobalSettings(AliasModel):
- general: General = General()
- rate_limiting_options: RateLimiting = RateLimiting()
- ui_options: UIOptions = UIOptions()
- generic_crawlers_instances: GenericCrawlerInstances = GenericCrawlerInstances()
+ general: General = Field(default_factory=General)
+ rate_limiting_options: RateLimiting = Field(default_factory=RateLimiting)
+ ui_options: UIOptions = Field(default_factory=UIOptions)
+ generic_crawlers_instances: GenericCrawlerInstances = Field(default_factory=GenericCrawlerInstances)
diff --git a/cyberdrop_dl/config/settings.py b/cyberdrop_dl/config/settings.py
index 9709c0d7f..41770388e 100644
--- a/cyberdrop_dl/config/settings.py
+++ b/cyberdrop_dl/config/settings.py
@@ -274,9 +274,9 @@ class IgnoreOptions(SettingsGroup):
class RuntimeOptions(SettingsGroup):
- log_level: NonNegativeInt | Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "DEBUG"
+ log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "DEBUG"
"Only log messages of this level or higher to the main log file"
- console_log_level: NonNegativeInt | Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] | None = None
+ console_log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] | None = None
"Only log messages of this level or higher to the console. An empty or `None` value will use the same level as `log_level`"
deep_scrape: bool = False
delete_partial_files: bool = False
@@ -296,28 +296,19 @@ class RuntimeOptions(SettingsGroup):
def normalize_log_level(cls, value: object) -> Any:
value = falsy_as_none(value)
if type(value) is str:
- try:
- return logging.getLevelNamesMapping()[value.upper()]
- except KeyError:
- raise ValueError(f"invalid log level name: {value!r}") from None
+ return value.upper()
return value
@property
def effective_log_level(self) -> int:
- if type(self.log_level) is str:
- return logging.getLevelNamesMapping()[self.log_level.upper()]
- assert type(self.log_level) is int
- return self.log_level
+ return logging.getLevelNamesMapping()[self.log_level]
@property
def effective_console_log_level(self) -> int:
- if type(self.console_log_level) is int and self.console_log_level > logging.CRITICAL:
- self.console_log_level = None
if not self.console_log_level:
return self.effective_log_level
- assert type(self.console_log_level) is int
- return self.console_log_level
+ return logging.getLevelNamesMapping()[self.console_log_level]
class Sorting(SettingsGroup):
@@ -399,16 +390,16 @@ class DupeCleanup(SettingsGroup):
@Parameter(name="*")
class ConfigSettings(AliasModel):
- browser_cookies: BrowserCookies = BrowserCookies()
- download_options: DownloadOptions = DownloadOptions()
- dupe_cleanup_options: DupeCleanup = DupeCleanup()
- file_size_limits: FileSizeLimits = FileSizeLimits()
- media_duration_limits: MediaDurationLimits = MediaDurationLimits()
- files: Files = Files()
- ignore_options: IgnoreOptions = IgnoreOptions()
- logs: Logs = Logs()
- runtime_options: RuntimeOptions = RuntimeOptions()
- sorting: Sorting = Sorting()
+ browser_cookies: BrowserCookies = Field(default_factory=BrowserCookies)
+ download_options: DownloadOptions = Field(default_factory=DownloadOptions)
+ dupe_cleanup_options: DupeCleanup = Field(default_factory=DupeCleanup)
+ file_size_limits: FileSizeLimits = Field(default_factory=FileSizeLimits)
+ media_duration_limits: MediaDurationLimits = Field(default_factory=MediaDurationLimits)
+ files: Files = Field(default_factory=Files)
+ ignore_options: IgnoreOptions = Field(default_factory=IgnoreOptions)
+ logs: Logs = Field(default_factory=Logs)
+ runtime_options: RuntimeOptions = Field(default_factory=RuntimeOptions)
+ sorting: Sorting = Field(default_factory=Sorting)
_resolved: bool = False
def resolve_paths(self) -> None:
diff --git a/cyberdrop_dl/ddos_guard.py b/cyberdrop_dl/ddos_guard.py
index 33234ae01..9213f15c1 100644
--- a/cyberdrop_dl/ddos_guard.py
+++ b/cyberdrop_dl/ddos_guard.py
@@ -143,7 +143,7 @@ class CloudFlareTurnstile(DDosGuard):
class BasedFlare(DDosGuard):
# TODO: add logic to solve it: https://gitgud.io/fatchan/haproxy-protection/-/blob/71015f402c49afcdcb3e70bc98dbaddc5ccbc74c/src/js/ch.js#L105
TITLES = ("Hold on...",)
- SELECTOR = ", ".join(("head[data-langjson*='Performance & security by BasedFlare')]", "body[data-pow][data-mode]"))
+ SELECTOR = ", ".join(("head[data-langjson*='Performance & security by BasedFlare']", "body[data-pow][data-mode]"))
@classmethod
@override
diff --git a/docs/reference/configuration-options/settings/runtime_options.md b/docs/reference/configuration-options/settings/runtime_options.md
index f07d737dd..96e25b3d1 100644
--- a/docs/reference/configuration-options/settings/runtime_options.md
+++ b/docs/reference/configuration-options/settings/runtime_options.md
@@ -4,15 +4,11 @@ These are higher level options that effect the overarching functions of the prog
## `console_log_level`
-| Type | Default |
-| ---------------- | ------- |
-| `NonNegativeInt` | `100` |
+| Type | Default |
+| ----------------------------------------------- | ------- |
+| `DEBUG, INFO, WARNING, ERROR, CRITICAL or None` | `None` |
-Same as `log_level` but it controls which messages are shown on the console.
-
-{% hint style="info" %}
-This option is ignored unless CDL is running with `--ui DISABLED`
-{% endhint %}
+Only log messages of this level or higher to the console. An empty or `None` value will use the same level as `log_level`
## `deep_scrape`
@@ -91,38 +87,24 @@ This option has no effect unless `send_unsupported_to_jdownloader` is `true`
## `log_level`
-| Type | Default |
-| ---------------- | ------- |
-| `NonNegativeInt` | `10` |
+| Type | Default |
+| --------------------------------------- | ------- |
+| `DEBUG, INFO, WARNING, ERROR, CRITICAL` | `DEBUG` |
-Defines the logging level for messages, according to [Python logging levels](https://docs.python.org/3/library/logging.html#levels). Only messages with a level equal or greater than this setting will be logged, with the exception of `NOTSET` which will disable all logging messages. Setting a value above 50 will also disable logging entirely.
+Only log messages of this level or higher to the main log file, according to [Python logging levels](https://docs.python.org/3/library/logging.html#levels).
-| Level | Value | Description |
-| ---------- | ----- | -------------------------------------------------------------------------------------------------------------- |
-| `NOTSET` | 0 | Disables all log messages |
-| `DEBUG` | 10 | Offers detailed information, typically useful to troubleshoot problems |
-| `INFO` | 20 | Provides general information about scrape and download progress |
+| Level | Value | Description |
+| ---------- | ----- | -------------------------------------------------------------------------------------------------- |
+| `DEBUG` | 10 | Offers detailed information, typically useful to troubleshoot problems |
+| `INFO` | 20 | Provides general information about scrape and download progress |
| `WARNING` | 30 | Potential issues or something that might need attention (e.g. `Login wasn't provided for <FORUM>`) |
-| `ERROR` | 40 | Serious problem preventing Cyberdrop-DL to execute some function |
-| `CRITICAL` | 50 | Fatal error that causes Cyberdrop-DL to exit immediately |
+| `ERROR` | 40 | Serious problem preventing Cyberdrop-DL to execute some function |
+| `CRITICAL` | 50 | Fatal error that causes Cyberdrop-DL to exit immediately |
{% hint style="info" %}
Using anything other that `DEBUG` makes troubleshooting issues harder. Practically speaking, you should _only_ change this if you expect CDL to run for an extended period (with a large number of input URLs) to minimize the log files sizes
{% endhint %}
-{% hint style="info" %}
-There is one more verbose level of logs: `DEVELOPER`
-
-It includes pager logs, posts logs, individual requests logs (their URLs and their response code), requests cache hits and misses, file system locks logs and local variable values from within a traceback. It's not exposed as a config option because it is too verbose.
-
-You can set the environment variable `CDL_DEBUG_LOG_FOLDER` to any valid folder and CDL will create an additional log file with the level set to `DEVELOPER` inside it.
-{% endhint %}
-
-{% hint style="warning" %}
-As the name suggests, the `DEVELOPER` log level is only meant for developers or, more generally, people that want and have the know how
-to troubleshoot CDL issues on their own. You should never share those logs with _anyone_ as it could potentially have raw information in the tracebacks like cookies, auth credentials, IPs, etc.
-{% endhint %}
-
## `send_unsupported_to_jdownloader`
| Type | Default |
diff --git a/tests/test_config.py b/tests/test_config.py
index 1ef7f256c..ef3857fdf 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -146,10 +146,12 @@ class TestRuntimeLogsConfig:
assert default.effective_console_log_level == expected.effective_console_log_level
def test_falsy_console_log_level(self) -> None:
- for a, b in [(30, None), (40, ""), (20, "none")]:
- config = self.parse(a, b)
- assert config.effective_log_level == a
- assert config.effective_console_log_level == a
+ for name, level, console_level in [("warning", 30, None), ("error", 40, ""), ("info", 20, "none")]:
+ config = self.parse(name, console_level)
+ assert config.log_level == name.upper()
+ assert config.console_log_level is None
+ assert config.effective_log_level == level
+ assert config.effective_console_log_level == level
def test_default_config_does_not_need_ffmpeg() -> None: