diff -Nru python-click-log-0.1.8/click_log/core.py python-click-log-0.2.1/click_log/core.py --- python-click-log-0.1.8/click_log/core.py 2016-12-17 12:03:49.000000000 +0000 +++ python-click-log-0.2.1/click_log/core.py 2017-09-25 18:00:57.000000000 +0000 @@ -1,9 +1,7 @@ # -*- coding: utf-8 -*- -import sys - -import functools import logging +import sys import click @@ -60,7 +58,7 @@ click.echo(msg, err=err) except (KeyboardInterrupt, SystemExit): raise - except: + except Exception: self.handleError(record) @@ -68,52 +66,17 @@ _default_handler.formatter = ColorFormatter() +def _normalize_logger(logger): + if not isinstance(logger, logging.Logger): + logger = logging.getLogger(logger) + return logger + + def basic_config(logger=None): '''Set up the default handler (:py:class:`ClickHandler`) and formatter (:py:class:`ColorFormatter`) on the given logger.''' - if not isinstance(logger, logging.Logger): - logger = logging.getLogger(logger) + logger = _normalize_logger(logger) logger.handlers = [_default_handler] logger.propagate = False return logger - - -def init(logger=None): - '''Set the application's logger and call :py:func:`basic_config` on it.''' - def decorator(f): - @functools.wraps(f) - def wrapper(*args, **kwargs): - m = _meta() - l = basic_config(logger=logger) - l.setLevel(m.get('level', DEFAULT_LEVEL)) - - if m.setdefault('logger', l) is not l: - raise RuntimeError('Only one main logger allowed.') - - return f(*args, **kwargs) - return wrapper - return decorator - - -def get_logger(): - '''Get the application's logger.''' - return _meta().get('logger') - - -def set_level(level): - '''Set the level for the application's logger.''' - - if not isinstance(level, int): - raise ValueError('Must be constant from `logging`.') - - logger = get_logger() - if logger is not None: - logger.setLevel(level) - - _meta()['level'] = level - - -def get_level(): - '''Get the level for the application's logger.''' - return _meta().get('level', DEFAULT_LEVEL) diff -Nru python-click-log-0.1.8/click_log/__init__.py python-click-log-0.2.1/click_log/__init__.py --- python-click-log-0.1.8/click_log/__init__.py 2016-12-17 12:03:49.000000000 +0000 +++ python-click-log-0.2.1/click_log/__init__.py 2017-09-25 18:00:57.000000000 +0000 @@ -3,7 +3,7 @@ import click -__version__ = '0.1.8' +__version__ = '0.2.1' if not hasattr(click, 'get_current_context'): @@ -13,9 +13,6 @@ ClickHandler, ColorFormatter, basic_config, - get_level, - init, - set_level, ) from .options import simple_verbosity_option diff -Nru python-click-log-0.1.8/click_log/options.py python-click-log-0.2.1/click_log/options.py --- python-click-log-0.1.8/click_log/options.py 2016-12-17 12:03:49.000000000 +0000 +++ python-click-log-0.2.1/click_log/options.py 2017-09-25 18:00:57.000000000 +0000 @@ -1,11 +1,10 @@ import logging import click +from .core import _normalize_logger -from .core import set_level - -def simple_verbosity_option(*names, **kwargs): +def simple_verbosity_option(logger=None, *names, **kwargs): '''A decorator that adds a `--verbosity, -v` option to the decorated command. @@ -15,6 +14,9 @@ if not names: names = ['--verbosity', '-v'] + if isinstance(logger, str) and logger.startswith('-'): + raise ValueError('Since click-log 0.2.0, the first argument must now ' + 'be a logger.') kwargs.setdefault('default', 'INFO') kwargs.setdefault('metavar', 'LVL') @@ -22,6 +24,8 @@ kwargs.setdefault('help', 'Either CRITICAL, ERROR, WARNING, INFO or DEBUG') kwargs.setdefault('is_eager', True) + logger = _normalize_logger(logger) + def decorator(f): def _set_level(ctx, param, value): x = getattr(logging, value.upper(), None) @@ -29,7 +33,7 @@ raise click.BadParameter( 'Must be CRITICAL, ERROR, WARNING, INFO or DEBUG, not {}' ) - set_level(x) + logger.setLevel(x) return click.option(*names, callback=_set_level, **kwargs)(f) return decorator diff -Nru python-click-log-0.1.8/debian/changelog python-click-log-0.2.1/debian/changelog --- python-click-log-0.1.8/debian/changelog 2016-12-28 22:02:59.000000000 +0000 +++ python-click-log-0.2.1/debian/changelog 2017-12-11 16:28:46.000000000 +0000 @@ -1,3 +1,18 @@ +python-click-log (0.2.1-1) unstable; urgency=medium + + * New upstream release + * Bump standards version to 4.1.2 (no changes) + + -- Filip Pytloun Mon, 11 Dec 2017 17:28:46 +0100 + +python-click-log (0.2.0-1) unstable; urgency=medium + + * New upstream release + * Bump debhelper version to 10 (no changes) + * Bump standards version to 4.0.0 (no changes) + + -- Filip Pytloun Wed, 06 Sep 2017 13:19:10 +0200 + python-click-log (0.1.8-1) unstable; urgency=medium * Team upload. diff -Nru python-click-log-0.1.8/debian/compat python-click-log-0.2.1/debian/compat --- python-click-log-0.1.8/debian/compat 2016-12-28 21:47:11.000000000 +0000 +++ python-click-log-0.2.1/debian/compat 2017-12-11 16:28:33.000000000 +0000 @@ -1 +1 @@ -9 +10 diff -Nru python-click-log-0.1.8/debian/control python-click-log-0.2.1/debian/control --- python-click-log-0.1.8/debian/control 2016-12-28 21:47:11.000000000 +0000 +++ python-click-log-0.2.1/debian/control 2017-12-11 16:28:42.000000000 +0000 @@ -3,7 +3,7 @@ Uploaders: Filip Pytloun Section: python Priority: optional -Build-Depends: debhelper (>= 9), +Build-Depends: debhelper (>= 10), dh-python (>= 2.20160609~), python-all, python-click, @@ -13,7 +13,7 @@ python3-click, python3-pytest, python3-setuptools, -Standards-Version: 3.9.8 +Standards-Version: 4.1.2 Testsuite: autopkgtest-pkg-python Homepage: https://github.com/click-contrib/click-log Vcs-Browser: https://anonscm.debian.org/cgit/python-modules/packages/python-click-log.git/ diff -Nru python-click-log-0.1.8/debian/.git-dpm python-click-log-0.2.1/debian/.git-dpm --- python-click-log-0.1.8/debian/.git-dpm 2016-12-28 21:47:11.000000000 +0000 +++ python-click-log-0.2.1/debian/.git-dpm 2017-12-11 16:28:33.000000000 +0000 @@ -1,11 +1,11 @@ # see git-dpm(1) from git-dpm package -e44e3a9caf9c6f05fbdf6667a6be6d662e56b8e7 -e44e3a9caf9c6f05fbdf6667a6be6d662e56b8e7 -f5d575527b24fe51899b9cfb40602ab4c7e62bfa -f5d575527b24fe51899b9cfb40602ab4c7e62bfa -python-click-log_0.1.8.orig.tar.gz -336cef0577ad84deae731e069c5d154624413681 -9025 +d42f8f888da3d532d4edfd4db15f91c646cfb28f +d42f8f888da3d532d4edfd4db15f91c646cfb28f +fa168cb0f6d77277ddaded92ec94e58e6b097126 +fa168cb0f6d77277ddaded92ec94e58e6b097126 +python-click-log_0.2.1.orig.tar.gz +581923c513f7dab4e9685f958652c5891e1876b0 +9326 debianTag="debian/%e%v" patchedTag="patched/%e%v" upstreamTag="upstream/%e%u" diff -Nru python-click-log-0.1.8/debian/patches/0001-Remove-embedded-image-in-docs-to-avoid-privacy-breac.patch python-click-log-0.2.1/debian/patches/0001-Remove-embedded-image-in-docs-to-avoid-privacy-breac.patch --- python-click-log-0.1.8/debian/patches/0001-Remove-embedded-image-in-docs-to-avoid-privacy-breac.patch 2016-12-28 21:47:11.000000000 +0000 +++ python-click-log-0.2.1/debian/patches/0001-Remove-embedded-image-in-docs-to-avoid-privacy-breac.patch 2017-12-11 16:28:33.000000000 +0000 @@ -1,4 +1,4 @@ -From e44e3a9caf9c6f05fbdf6667a6be6d662e56b8e7 Mon Sep 17 00:00:00 2001 +From d42f8f888da3d532d4edfd4db15f91c646cfb28f Mon Sep 17 00:00:00 2001 From: Filip Pytloun Date: Tue, 9 Aug 2016 11:45:44 +0200 Subject: Remove embedded image in docs to avoid privacy breach diff -Nru python-click-log-0.1.8/docs/index.rst python-click-log-0.2.1/docs/index.rst --- python-click-log-0.1.8/docs/index.rst 2016-12-17 12:03:49.000000000 +0000 +++ python-click-log-0.2.1/docs/index.rst 2017-09-25 18:00:57.000000000 +0000 @@ -65,10 +65,10 @@ import logging logger = logging.getLogger(__name__) + click_log.basic_config(logger) @click.command() - @click_log.simple_verbosity_option() - @click_log.init(__name__) + @click_log.simple_verbosity_option(logger) def cli(): logger.info("Dividing by zero.") @@ -95,18 +95,19 @@ that takes a (case-insensitive) value of ``DEBUG``, ``INFO``, ``WARNING``, ``ERROR``, or ``CRITICAL``, and calls :py:func:`set_level` accordingly. +.. note:: + + Make sure to define the `simple_verbosity_option` as early as possible. + Otherwise logging setup will not be early enough for some of your other + eager options. + API === -.. autofunction:: init - -.. autofunction:: simple_verbosity_option .. autofunction:: basic_config -.. autofunction:: get_level - -.. autofunction:: set_level +.. autofunction:: simple_verbosity_option Classes ------- diff -Nru python-click-log-0.1.8/setup.py python-click-log-0.2.1/setup.py --- python-click-log-0.1.8/setup.py 2016-12-17 12:03:49.000000000 +0000 +++ python-click-log-0.2.1/setup.py 2017-09-25 18:00:57.000000000 +0000 @@ -20,6 +20,26 @@ url='https://github.com/click-contrib/click-log', license='MIT', long_description=open('README.rst').read(), + classifiers=[ + # See: https://pypi.python.org/pypi?:action=list_classifiers + 'Development Status :: 4 - Beta', + 'Environment :: Console', + 'Environment :: Plugins', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + # List of python versions and their support status: + # https://en.wikipedia.org/wiki/CPython#Version_history + 'Programming Language :: Python', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: Implementation :: CPython', + 'Topic :: System :: Logging', + ], packages=['click_log'], install_requires=[ 'click', diff -Nru python-click-log-0.1.8/tests/test_basic.py python-click-log-0.2.1/tests/test_basic.py --- python-click-log-0.1.8/tests/test_basic.py 2016-12-17 12:03:49.000000000 +0000 +++ python-click-log-0.2.1/tests/test_basic.py 2017-09-25 18:00:57.000000000 +0000 @@ -11,6 +11,8 @@ test_logger = logging.getLogger(__name__) +click_log.basic_config(test_logger) +test_logger.level = logging.INFO @pytest.fixture @@ -20,7 +22,6 @@ def test_basic(runner): @click.command() - @click_log.init() def cli(): test_logger.info('hey') test_logger.error('damn') @@ -32,7 +33,6 @@ def test_multilines(runner): @click.command() - @click_log.init() def cli(): test_logger.warning(""" Lorem ipsum dolor sit amet, @@ -50,7 +50,6 @@ def test_unicode(runner): @click.command() - @click_log.init() def cli(): test_logger.error(u""" ❤️ 💔 💌 💕 💞 💓 💗 💖 💘 @@ -66,7 +65,6 @@ def test_weird_types_log(runner): @click.command() - @click_log.init() def cli(): test_logger.error(42) test_logger.error('42') @@ -76,3 +74,22 @@ result = runner.invoke(cli, catch_exceptions=False) assert not result.exception assert result.output == 'error: 42\n' * 4 + + +def test_early_logging(runner): + i = None + + def callback(context, param, value): + test_logger.debug('catch me {}!'.format(i)) + + @click.command() + @click_log.simple_verbosity_option(test_logger) + @click.option('--config', is_eager=True, default=None, expose_value=False, + callback=callback) + def cli(): + test_logger.debug('hello') + + for i in range(2): + result = runner.invoke(cli, ['-v', 'debug'], catch_exceptions=False) + assert 'debug: hello' in result.output + assert 'debug: catch me {}!'.format(i) in result.output