Skip to content

Commit

Permalink
Change logging level handling
Browse files Browse the repository at this point in the history
- Set default logging level to INFO
- Add command-line option 'quiet' to set to DEBUG

Resolves #10.
  • Loading branch information
JeanFred committed Jan 17, 2015
1 parent 0e9670f commit d6b7d29
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions commonsdownloader/commonsdownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def is_file_in_cache(file_name, width, cache):
def write_file_to_cache(file_name, width, cache_fh):
"""Write the given file on cache."""
cache_fh.write("%s,%s\n" % (file_name, str(width)))
logging.debug("Wrote file %s to cache" % file_name)


def download_files_if_not_in_cache(files_iterator, output_path):
Expand Down Expand Up @@ -115,16 +116,23 @@ def main():
type=int,
default=100,
help='The width of the thumbnail (default: 100)')
parser.add_argument("-v",
action="count",
dest="verbose",
default=0,
help="Verbosity level. -v for INFO, -vv for DEBUG")
group = parser.add_mutually_exclusive_group()
group.add_argument("-v",
action="count",
dest="verbose",
default=1,
help="Verbosity level. -v for DEBUG")
group.add_argument("-q", "--quiet",
action="store_const",
dest="verbose",
const=0,
help="To silence the INFO messages")
args = parser.parse_args()
logging_map = {0: logging.WARNING,
1: logging.INFO,
2: logging.DEBUG}
logging.basicConfig(level=logging_map[args.verbose])
logging_level = logging_map.get(args.verbose, logging.DEBUG)
logging.basicConfig(level=logging_level)
logging.info("Starting")

if args.file_list:
Expand Down

0 comments on commit d6b7d29

Please sign in to comment.