From d02b5bb9ad075e96236c37a7abd245b2532681f0 Mon Sep 17 00:00:00 2001 From: Zhiming Wang Date: Sat, 19 Mar 2016 22:51:09 -0700 Subject: [PATCH] common.py: Print URL of get_content call when --debug is enabled Use logging, and raise the root logger level from WARNING (default) to DEBUG when --debug is enabled. This logging facility can be extended to other functions. --- src/you_get/common.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/you_get/common.py b/src/you_get/common.py index f15481a3..a417bcc7 100755 --- a/src/you_get/common.py +++ b/src/you_get/common.py @@ -91,6 +91,7 @@ SITES = { import getopt import json import locale +import logging import os import platform import re @@ -298,6 +299,8 @@ def get_content(url, headers={}, decoded=True): The content as a string. """ + logging.debug('get_content: %s' % url) + req = request.Request(url, headers=headers) if cookies: cookies.add_cookie_header(req) @@ -1032,6 +1035,8 @@ def script_main(script_name, download, download_playlist, **kwargs): % get_version(kwargs['repo_path'] if 'repo_path' in kwargs else __version__)) + logging.basicConfig(format='[%(levelname)s] %(message)s') + help = 'Usage: %s [OPTION]... [URL]...\n\n' % script_name help += '''Startup options: -V | --version Print version and exit. @@ -1055,7 +1060,7 @@ def script_main(script_name, download, download_playlist, **kwargs): -x | --http-proxy Use an HTTP proxy for downloading. -y | --extractor-proxy Use an HTTP proxy for extracting only. --no-proxy Never use a proxy. - -d | --debug Show traceback for debugging. + -d | --debug Show traceback and other debug info. ''' short_opts = 'Vhfiuc:ndF:O:o:p:x:y:' @@ -1145,6 +1150,8 @@ def script_main(script_name, download, download_playlist, **kwargs): proxy = '' elif o in ('-d', '--debug'): traceback = True + # Set level of root logger to DEBUG + logging.getLogger().setLevel(logging.DEBUG) elif o in ('-F', '--format', '--stream', '--itag'): stream_id = a elif o in ('-O', '--output-filename'):