diff --git a/twitchdl/cli.py b/twitchdl/cli.py index e198634..7265666 100644 --- a/twitchdl/cli.py +++ b/twitchdl/cli.py @@ -80,11 +80,12 @@ def validate_rate(_ctx: click.Context, _param: click.Parameter, value: str) -> O @click.group(context_settings=CONTEXT) -@click.option("--debug/--no-debug", default=False, help="Log debug info to stderr") +@click.option("--debug/--no-debug", default=False, help="Enable debug logging to stderr") +@click.option("--verbose/--no-verbose", default=False, help="More verbose debug logging") @click.option("--color/--no-color", default=sys.stdout.isatty(), help="Use ANSI color in output") @click.version_option(package_name="twitch-dl") @click.pass_context -def cli(ctx: click.Context, color: bool, debug: bool): +def cli(ctx: click.Context, color: bool, debug: bool, verbose: bool): """twitch-dl - twitch.tv downloader https://twitch-dl.bezdomni.net/ @@ -92,7 +93,7 @@ def cli(ctx: click.Context, color: bool, debug: bool): ctx.color = color if debug: - logging.basicConfig(level=logging.DEBUG) + logging.basicConfig(level=logging.DEBUG if verbose else logging.INFO) logging.getLogger("httpx").setLevel(logging.WARN) logging.getLogger("httpcore").setLevel(logging.WARN) diff --git a/twitchdl/http.py b/twitchdl/http.py index 25e93e1..8d1cbfe 100644 --- a/twitchdl/http.py +++ b/twitchdl/http.py @@ -149,12 +149,16 @@ async def download_all( def download_file(url: str, target: Path, retries: int = RETRY_COUNT) -> None: """Download URL to given target path with retries""" error_message = "" - for _ in range(retries): + for r in range(retries): try: + retry_info = f" (retry {r})" if r > 0 else "" + logger.info(f"Downloading {url} to {target}{retry_info}") return _do_download_file(url, target) except httpx.HTTPStatusError as ex: + logger.error(ex) error_message = f"Server responded with HTTP {ex.response.status_code}" except httpx.RequestError as ex: + logger.error(ex) error_message = str(ex) raise ConsoleError(f"Failed downloading after {retries} attempts: {error_message}") diff --git a/twitchdl/twitch.py b/twitchdl/twitch.py index 12bba8e..d6681e4 100644 --- a/twitchdl/twitch.py +++ b/twitchdl/twitch.py @@ -22,6 +22,7 @@ from twitchdl.entities import ( VideosType, ) from twitchdl.exceptions import ConsoleError +from twitchdl.utils import format_size class GQLError(click.ClickException): @@ -78,15 +79,16 @@ logger = logging.getLogger(__name__) def log_request(request: httpx.Request): - logger.debug(f"--> {request.method} {request.url}") + logger.info(f"--> {request.method} {request.url}") if request.content: logger.debug(f"--> {request.content}") -def log_response(response: httpx.Response, duration: float): +def log_response(response: httpx.Response, duration_seconds: float): request = response.request - duration_ms = int(1000 * duration) - logger.debug(f"<-- {request.method} {request.url} HTTP {response.status_code} {duration_ms}ms") + duration = f"{int(1000 * duration_seconds)}ms" + size = format_size(len(response.content)) + logger.info(f"<-- {request.method} {request.url} HTTP {response.status_code} {duration} {size}") if response.content: logger.debug(f"<-- {response.content}")