Skip to content

Bulk asynchronous downloader for multiple file hosts

feat: add `--logs.http-traffic` option

NTFSvolume65f6c7de114c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8578f6cf4..3a0763354 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,14 +26,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
+- New `--logs.http-traffic` option
- Support direct local connection to JDownloader using their deprecated API
- `wreq` as optional HTTP backend for browser impersonation (via the `wreq` extra)
### Changed
- Log HTTP requests made to JDownloader
+- Logs of HTTP requests/responses will be emitted at INFO instead of DEBUG level
- If scraping has already started, sending `SIGINT` (`Ctrl + C`) to the process will stop all scraping but will continue with post-runtime actions
(sorting, hashing, send notifications, etc..). Press `Ctrl + C` again to force quit
+- Reduced the maximum size the log file can have to be sent as attachment in notifications, from 25 MB to 20 MB.
## [10.5.0] - 2026-08-15
diff --git a/cyberdrop_dl/clients/__init__.py b/cyberdrop_dl/clients/__init__.py
index 74398a73d..dad6912ba 100644
--- a/cyberdrop_dl/clients/__init__.py
+++ b/cyberdrop_dl/clients/__init__.py
@@ -1,3 +1,18 @@
+import logging
from typing import Literal
+from cyberdrop_dl import signature
+from cyberdrop_dl.logs import LOG_HTTP_TRAFFIC
+
HttpMethod = Literal["GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "TRACE", "PATCH", "QUERY"]
+
+
+class TrafficLogger(logging.LoggerAdapter[logging.Logger]):
+ @signature.copy(logging.LoggerAdapter.info)
+ def traffic(self, msg, *args, **kwargs) -> None:
+ if LOG_HTTP_TRAFFIC.get():
+ self.log(logging.INFO, msg, *args, **kwargs)
+
+
+def get_logger(name: str) -> TrafficLogger:
+ return TrafficLogger(logging.getLogger(name))
diff --git a/cyberdrop_dl/clients/flaresolverr.py b/cyberdrop_dl/clients/flaresolverr.py
index 39fce4e3b..69d7d9f01 100644
--- a/cyberdrop_dl/clients/flaresolverr.py
+++ b/cyberdrop_dl/clients/flaresolverr.py
@@ -4,7 +4,6 @@ import asyncio
import contextlib
import dataclasses
import itertools
-import logging
import time
from enum import StrEnum
from http.cookies import SimpleCookie
@@ -14,6 +13,7 @@ import aiohttp
from multidict import CIMultiDict, CIMultiDictProxy
from cyberdrop_dl import ddos_guard
+from cyberdrop_dl.clients import get_logger
from cyberdrop_dl.exceptions import DDOSGuardError, FlaresolverrError
from cyberdrop_dl.progress.scraping import show_msg
from cyberdrop_dl.url_objects import AbsoluteHttpURL
@@ -23,7 +23,7 @@ if TYPE_CHECKING:
from collections.abc import Callable, Generator, Iterable, Mapping
-logger = logging.getLogger(__name__)
+logger = get_logger(__name__)
class Command(StrEnum):
@@ -197,14 +197,14 @@ class Client:
else f"Waiting for Flaresolverr [{request_id}]"
)
with show_msg(msg):
- logger.debug("Making FlareSolverr request [id=%s]\n%s", request_id, params)
+ logger.traffic("Making FlareSolverr request [id=%s]\n%s", request_id, params)
async with self._aiohttp_session.post(self.url, json=params, **timeout) as response:
resp_json = await response.json()
try:
resp = Response.from_dict(resp_json)
resp.id = str(request_id)
finally:
- logger.debug(
+ logger.traffic(
"Finished FlareSolverr request [id=%s]\n%s", request_id, _LazyResponseLog(resp_json)
)
return resp
diff --git a/cyberdrop_dl/clients/http.py b/cyberdrop_dl/clients/http.py
index 45d69a4f6..9ef0a5c34 100644
--- a/cyberdrop_dl/clients/http.py
+++ b/cyberdrop_dl/clients/http.py
@@ -4,7 +4,6 @@ import asyncio
import contextlib
import dataclasses
import http.cookies
-import logging
import time
from contextvars import ContextVar
from http import HTTPStatus
@@ -14,7 +13,7 @@ import aiohttp
from aiohttp import hdrs
from cyberdrop_dl import aio, cookies, ddos_guard
-from cyberdrop_dl.clients import curl_cffi, flaresolverr, tcp, wreq
+from cyberdrop_dl.clients import curl_cffi, flaresolverr, get_logger, tcp, wreq
from cyberdrop_dl.clients.request import Request, RequestParams
from cyberdrop_dl.clients.response import AbstractResponse
from cyberdrop_dl.cookies import make_simple_cookie
@@ -44,7 +43,7 @@ type JSONCheck = Callable[[Any, AbstractResponse[Any]], None]
JSON_CHECK: ContextVar[JSONCheck | None] = ContextVar("JSON_CHECK", default=None)
-logger = logging.getLogger(__name__)
+logger = get_logger(__name__)
class _LazyResponseLog:
@@ -256,11 +255,11 @@ class HTTPClient:
@contextlib.asynccontextmanager
async def _request(self, request: Request) -> AsyncGenerator[AbstractResponse[Any]]:
- logger.debug("Starting %s request [id=%s]\n%s", request.method, request.id, request)
+ logger.traffic("Starting %s request [id=%s]\n%s", request.method, request.id, request)
exc = None
async with self.__request(request) as resp:
resp.id = request.id
- logger.debug("Finished %s request [id=%s]\n%s", request.method, request.id, _LazyResponseLog(resp))
+ logger.traffic("Finished %s request [id=%s]\n%s", request.method, request.id, _LazyResponseLog(resp))
try:
yield resp
except Exception as e:
@@ -268,7 +267,7 @@ class HTTPClient:
raise
finally:
if resp.has_content_not_logged:
- logger.debug(
+ logger.traffic(
"Content from %s request [id=%s]\n%s",
request.method,
request.id,
diff --git a/cyberdrop_dl/commands/scrape.py b/cyberdrop_dl/commands/scrape.py
index 4faa5af01..9dfc75c8e 100644
--- a/cyberdrop_dl/commands/scrape.py
+++ b/cyberdrop_dl/commands/scrape.py
@@ -30,7 +30,11 @@ if TYPE_CHECKING:
def scrape(manager: Manager, source: URLsSource | RetryScrapeSource) -> None:
from cyberdrop_dl import aio
- with setup_file_logging(manager.config.logs.files.main, level=manager.config.logs.effective_level):
+ with setup_file_logging(
+ manager.config.logs.files.main,
+ level=manager.config.logs.effective_level,
+ log_http_traffic=manager.config.logs.http_traffic,
+ ):
aio.run(_scrape(manager, source))
diff --git a/cyberdrop_dl/config/default.yaml b/cyberdrop_dl/config/default.yaml
index 47abe1025..255e01cbd 100644
--- a/cyberdrop_dl/config/default.yaml
+++ b/cyberdrop_dl/config/default.yaml
@@ -138,6 +138,7 @@ logs:
scrape_errors: scrape_errors.csv
unsupported: unsupported.csv
folder: null
+ http_traffic: true
level: DEBUG
rotate: false
max_children:
diff --git a/cyberdrop_dl/config/schema.json b/cyberdrop_dl/config/schema.json
index d9e0449da..cbaa25571 100644
--- a/cyberdrop_dl/config/schema.json
+++ b/cyberdrop_dl/config/schema.json
@@ -729,6 +729,11 @@
"$ref": "#/$defs/FalsyAsNone_LogLevel_",
"default": null
},
+ "http_traffic": {
+ "default": true,
+ "title": "Http Traffic",
+ "type": "boolean"
+ },
"files": {
"$ref": "#/$defs/LogFiles"
},
diff --git a/cyberdrop_dl/config/settings.py b/cyberdrop_dl/config/settings.py
index bc20ea05b..2350803eb 100644
--- a/cyberdrop_dl/config/settings.py
+++ b/cyberdrop_dl/config/settings.py
@@ -90,6 +90,9 @@ class Logs(ConfigGroup, name=None): # noqa: PLW1641
console_level: FalsyAsNone[LogLevel] = 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`"
+ http_traffic: Annotated[bool, Parameter(alias="--print-traffic")] = True
+ "Log HTTP requests and responses (at INFO level)"
+
files: LogFiles = Field(default_factory=LogFiles)
folder: FalsyAsNone[Path] = None
"Base folder to prepend to log files paths (if they are not absolute)"
diff --git a/cyberdrop_dl/logs.py b/cyberdrop_dl/logs.py
index a75a3ceb6..07b87f1c0 100644
--- a/cyberdrop_dl/logs.py
+++ b/cyberdrop_dl/logs.py
@@ -44,6 +44,7 @@ _DEFAULT_CONSOLE_WIDTH = 240
_MAIN_LOG_LISTENER: ContextVar[QueueListener] = ContextVar("_MAIN_LOG_LISTENER")
_CONSOLE_LOG_LISTENER: ContextVar[QueueListener] = ContextVar("_CONSOLE_LOG_LISTENER")
_LOG_TO_CONSOLE: ContextVar[bool] = ContextVar("LOG_TO_CONSOLE", default=True)
+LOG_HTTP_TRAFFIC: ContextVar[bool] = ContextVar("LOG_HTTP_TRAFFIC", default=True)
MAX_ATTACHMENT_SIZE = 20 * 1e6
@@ -335,10 +336,17 @@ def setup_console_logging() -> Generator[None]:
@contextlib.contextmanager
-def setup_file_logging(file: Path, /, *, level: int = logging.DEBUG) -> Generator[None]:
+def setup_file_logging(
+ file: Path,
+ /,
+ *,
+ level: int = logging.DEBUG,
+ log_http_traffic: bool = True,
+) -> Generator[None]:
file.parent.mkdir(parents=True, exist_ok=True)
import mega
+ LOG_HTTP_TRAFFIC.set(log_http_traffic)
if "pytest" not in sys.modules:
logging.captureWarnings(capture=True)
@@ -346,7 +354,7 @@ def setup_file_logging(file: Path, /, *, level: int = logging.DEBUG) -> Generato
_setup_debug_logger() as debug_log_file,
file.open("w", encoding="utf8") as fp,
enter_context(MAIN_LOG_FILE, file),
- enter_context(mega.LOG_HTTP_TRAFFIC, True),
+ enter_context(mega.LOG_HTTP_TRAFFIC, log_http_traffic),
enter_context(mega.LOG_FILE_PROGRESS, False),
_threaded_logger(
log_handler=LogHandler(
diff --git a/docs/reference/config/logs.md b/docs/reference/config/logs.md
index 7a2c5e961..84c32c424 100644
--- a/docs/reference/config/logs.md
+++ b/docs/reference/config/logs.md
@@ -41,6 +41,19 @@ logs:
level: null
```
+# `http_traffic`
+
+| Type | Default |
+| ------ | ------- |
+| `bool` | `false` |
+
+Log HTTP requests and responses (at INFO level)
+
+```yaml
+logs:
+ http_traffic: false
+```
+
# `expire_after`
| Type | Default |