pax_global_header00006660000000000000000000000064131622421310014505gustar00rootroot0000000000000052 comment=7013ba44b93cf2e14cfe145174c1389b96cc2da0 click-log-0.2.1/000077500000000000000000000000001316224213100133515ustar00rootroot00000000000000click-log-0.2.1/.gitignore000066400000000000000000000001411316224213100153350ustar00rootroot00000000000000.DS_Store *.pyc *.pyo *.egg-ignore *.egg-info dist build/ docs/_build click.egg-info .tox .cache click-log-0.2.1/.travis.yml000066400000000000000000000001511316224213100154570ustar00rootroot00000000000000language: python python: - 2.7 - pypy - 3.3 - 3.4 install: pip install tox script: tox click-log-0.2.1/LICENSE000066400000000000000000000020741316224213100143610ustar00rootroot00000000000000Copyright (c) 2014-2015 Markus Unterwaditzer & contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. click-log-0.2.1/MANIFEST.in000066400000000000000000000002301316224213100151020ustar00rootroot00000000000000include LICENSE include Makefile recursive-include docs * recursive-include tests * prune docs/_build global-exclude *.py[cdo] __pycache__ *.so *.pyd click-log-0.2.1/Makefile000066400000000000000000000000631316224213100150100ustar00rootroot00000000000000release: python setup.py sdist bdist_wheel upload click-log-0.2.1/README.rst000066400000000000000000000005551316224213100150450ustar00rootroot00000000000000click-log ========= .. image:: https://travis-ci.org/click-contrib/click-log.svg?branch=master :target: https://travis-ci.org/click-contrib/click-log Integrates logging with click. - `Documentation `_ - `Source code `_ License ======= Licensed under the MIT, see ``LICENSE``. click-log-0.2.1/click_log/000077500000000000000000000000001316224213100152775ustar00rootroot00000000000000click-log-0.2.1/click_log/__init__.py000066400000000000000000000004471316224213100174150ustar00rootroot00000000000000# -*- coding: utf-8 -*- # flake8: noqa import click __version__ = '0.2.1' if not hasattr(click, 'get_current_context'): raise RuntimeError('You need Click 5.0.') from .core import ( ClickHandler, ColorFormatter, basic_config, ) from .options import simple_verbosity_option click-log-0.2.1/click_log/core.py000066400000000000000000000042051316224213100166020ustar00rootroot00000000000000# -*- coding: utf-8 -*- import logging import sys import click _ctx = click.get_current_context LOGGER_KEY = __name__ + '.logger' DEFAULT_LEVEL = logging.INFO PY2 = sys.version_info[0] == 2 if PY2: text_type = unicode # noqa else: text_type = str def _meta(): return _ctx().meta.setdefault(LOGGER_KEY, {}) class ColorFormatter(logging.Formatter): colors = { 'error': dict(fg='red'), 'exception': dict(fg='red'), 'critical': dict(fg='red'), 'debug': dict(fg='blue'), 'warning': dict(fg='yellow') } def format(self, record): if not record.exc_info: level = record.levelname.lower() if level in self.colors: prefix = click.style('{}: '.format(level), **self.colors[level]) msg = record.msg if not PY2 and isinstance(msg, bytes): msg = msg.decode(sys.getfilesystemencoding(), 'replace') elif not isinstance(msg, (text_type, bytes)): msg = str(msg) record.msg = '\n'.join(prefix + x for x in msg.splitlines()) return logging.Formatter.format(self, record) class ClickHandler(logging.Handler): def emit(self, record): try: msg = self.format(record) level = record.levelname.lower() err = level in ('warning', 'error', 'exception', 'critical') click.echo(msg, err=err) except (KeyboardInterrupt, SystemExit): raise except Exception: self.handleError(record) _default_handler = ClickHandler() _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.''' logger = _normalize_logger(logger) logger.handlers = [_default_handler] logger.propagate = False return logger click-log-0.2.1/click_log/options.py000066400000000000000000000023761316224213100173540ustar00rootroot00000000000000import logging import click from .core import _normalize_logger def simple_verbosity_option(logger=None, *names, **kwargs): '''A decorator that adds a `--verbosity, -v` option to the decorated command. Name can be configured through ``*names``. Keyword arguments are passed to the underlying ``click.option`` decorator. ''' 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') kwargs.setdefault('expose_value', False) 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) if x is None: raise click.BadParameter( 'Must be CRITICAL, ERROR, WARNING, INFO or DEBUG, not {}' ) logger.setLevel(x) return click.option(*names, callback=_set_level, **kwargs)(f) return decorator click-log-0.2.1/docs/000077500000000000000000000000001316224213100143015ustar00rootroot00000000000000click-log-0.2.1/docs/Makefile000066400000000000000000000176141316224213100157520ustar00rootroot00000000000000# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = _build # User-friendly check for sphinx-build ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don\'t have Sphinx installed, grab it from http://sphinx-doc.org/) endif # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " applehelp to make an Apple Help Book" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " epub3 to make an epub3" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" @echo " text to make text files" @echo " man to make manual pages" @echo " texinfo to make Texinfo files" @echo " info to make Texinfo files and run them through makeinfo" @echo " gettext to make PO message catalogs" @echo " changes to make an overview of all changed/added/deprecated items" @echo " xml to make Docutils-native XML files" @echo " pseudoxml to make pseudoxml-XML files for display purposes" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" @echo " coverage to run coverage check of the documentation (if enabled)" @echo " dummy to check syntax errors of document sources" .PHONY: clean clean: rm -rf $(BUILDDIR)/* .PHONY: html html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." .PHONY: dirhtml dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." .PHONY: singlehtml singlehtml: $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." .PHONY: pickle pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." .PHONY: json json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." .PHONY: htmlhelp htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." .PHONY: qthelp qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/click-log.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/click-log.qhc" .PHONY: applehelp applehelp: $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp @echo @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." @echo "N.B. You won't be able to view it unless you put it in" \ "~/Library/Documentation/Help or install it in your application" \ "bundle." .PHONY: devhelp devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" @echo "# mkdir -p $$HOME/.local/share/devhelp/click-log" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/click-log" @echo "# devhelp" .PHONY: epub epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." .PHONY: epub3 epub3: $(SPHINXBUILD) -b epub3 $(ALLSPHINXOPTS) $(BUILDDIR)/epub3 @echo @echo "Build finished. The epub3 file is in $(BUILDDIR)/epub3." .PHONY: latex latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." .PHONY: latexpdf latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." $(MAKE) -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." .PHONY: latexpdfja latexpdfja: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through platex and dvipdfmx..." $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." .PHONY: text text: $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." .PHONY: man man: $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." .PHONY: texinfo texinfo: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." @echo "Run \`make' in that directory to run these through makeinfo" \ "(use \`make info' here to do that automatically)." .PHONY: info info: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo "Running Texinfo files through makeinfo..." make -C $(BUILDDIR)/texinfo info @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." .PHONY: gettext gettext: $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale @echo @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." .PHONY: changes changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." .PHONY: linkcheck linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." .PHONY: doctest doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." .PHONY: coverage coverage: $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage @echo "Testing of coverage in the sources finished, look at the " \ "results in $(BUILDDIR)/coverage/python.txt." .PHONY: xml xml: $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml @echo @echo "Build finished. The XML files are in $(BUILDDIR)/xml." .PHONY: pseudoxml pseudoxml: $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml @echo @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." .PHONY: dummy dummy: $(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy @echo @echo "Build finished. Dummy builder generates no files." click-log-0.2.1/docs/conf.py000066400000000000000000000025201316224213100155770ustar00rootroot00000000000000# -*- coding: utf-8 -*- import sys import os import click_log extensions = ['sphinx.ext.autodoc'] templates_path = ['_templates'] source_suffix = '.rst' master_doc = 'index' project = 'click-log' copyright = '2016, Markus Unterwaditzer & contributors' author = 'Markus Unterwaditzer & contributors' release = click_log.__version__ version = '.'.join(release.split('.')[:2]) # The short X.Y version. exclude_patterns = ['_build'] pygments_style = 'sphinx' on_rtd = os.environ.get('READTHEDOCS', None) == 'True' try: import sphinx_rtd_theme html_theme = 'sphinx_rtd_theme' html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] except ImportError: html_theme = 'default' if not on_rtd: print('-' * 74) print('Warning: sphinx-rtd-theme not installed, building with default ' 'theme.') print('-' * 74) html_static_path = ['_static'] htmlhelp_basename = 'click-logdoc' latex_elements = {} latex_documents = [ (master_doc, 'click-log.tex', 'click-log Documentation', 'Markus Unterwaditzer \\& contributors', 'manual'), ] man_pages = [ (master_doc, 'click-log', 'click-log Documentation', [author], 1) ] texinfo_documents = [ (master_doc, 'click-log', 'click-log Documentation', author, 'click-log', 'One line description of project.', 'Miscellaneous'), ] click-log-0.2.1/docs/index.rst000066400000000000000000000062211316224213100161430ustar00rootroot00000000000000============================================================== Click-log: Simple and beautiful logging for click applications ============================================================== .. include:: ../README.rst .. toctree:: :maxdepth: 2 .. module:: click_log Getting started =============== Assuming you have this Click application:: @click.command() def cli(): click.echo("Dividing by zero.") try: 1 / 0 except: click.echo("ERROR: Failed to divide by zero.") Ignore the application's core functionality for a moment. The much more pressing question here is: How do we add an option to not print anything on success? We could try this:: @click.command() @click.option('--quiet', default=False, is_flag=True) def cli(quiet): if not quiet: click.echo("Dividing by zero.") try: 1 / 0 except: click.echo("ERROR: Failed to divide by zero.") Wrapping if-statements around each ``echo``-call is cumbersome though. And with that, we discover logging:: import logging logger = logging.getLogger(__name__) # More setup for logging handlers here @click.command() @click.option('--quiet', default=False, is_flag=True) def cli(quiet): if quiet: logger.setLevel(logging.ERROR) else: logger.setLevel(logging.INFO) ... Logging is a better solution, but partly because Python's logging module aims to be so generic, it doesn't come with sensible defaults for CLI applications. At some point you might also want to expose more logging levels through more options, at which point the boilerplate code grows even more. This is where click-log comes in:: import logging logger = logging.getLogger(__name__) click_log.basic_config(logger) @click.command() @click_log.simple_verbosity_option(logger) def cli(): logger.info("Dividing by zero.") try: 1 / 0 except: logger.error("Failed to divide by zero.") The output will look like this:: Dividing by zero. error: Failed to divide by zero. The ``error:``-prefix will be red, unless the output is piped to another command. Under the hood, click-log will get the logger by the given name, and store it on the click context object. You can then use :py:func:`get_level` and :py:func:`set_level`. Those functions will look up the logger from the context object without you having to pass any logger object or name. The :py:func:`simple_verbosity_option` decorator adds a ``--verbosity`` option 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:: basic_config .. autofunction:: simple_verbosity_option Classes ------- .. autoclass:: ClickHandler .. autoclass:: ColorFormatter Indices and tables ================== * :ref:`genindex` * :ref:`modindex` * :ref:`search` click-log-0.2.1/docs/make.bat000066400000000000000000000170721316224213100157150ustar00rootroot00000000000000@ECHO OFF REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( set SPHINXBUILD=sphinx-build ) set BUILDDIR=_build set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . set I18NSPHINXOPTS=%SPHINXOPTS% . if NOT "%PAPER%" == "" ( set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% ) if "%1" == "" goto help if "%1" == "help" ( :help echo.Please use `make ^` where ^ is one of echo. html to make standalone HTML files echo. dirhtml to make HTML files named index.html in directories echo. singlehtml to make a single large HTML file echo. pickle to make pickle files echo. json to make JSON files echo. htmlhelp to make HTML files and a HTML help project echo. qthelp to make HTML files and a qthelp project echo. devhelp to make HTML files and a Devhelp project echo. epub to make an epub echo. epub3 to make an epub3 echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter echo. text to make text files echo. man to make manual pages echo. texinfo to make Texinfo files echo. gettext to make PO message catalogs echo. changes to make an overview over all changed/added/deprecated items echo. xml to make Docutils-native XML files echo. pseudoxml to make pseudoxml-XML files for display purposes echo. linkcheck to check all external links for integrity echo. doctest to run all doctests embedded in the documentation if enabled echo. coverage to run coverage check of the documentation if enabled echo. dummy to check syntax errors of document sources goto end ) if "%1" == "clean" ( for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i del /q /s %BUILDDIR%\* goto end ) REM Check if sphinx-build is available and fallback to Python version if any %SPHINXBUILD% 1>NUL 2>NUL if errorlevel 9009 goto sphinx_python goto sphinx_ok :sphinx_python set SPHINXBUILD=python -m sphinx.__init__ %SPHINXBUILD% 2> nul if errorlevel 9009 ( echo. echo.The 'sphinx-build' command was not found. Make sure you have Sphinx echo.installed, then set the SPHINXBUILD environment variable to point echo.to the full path of the 'sphinx-build' executable. Alternatively you echo.may add the Sphinx directory to PATH. echo. echo.If you don't have Sphinx installed, grab it from echo.http://sphinx-doc.org/ exit /b 1 ) :sphinx_ok if "%1" == "html" ( %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/html. goto end ) if "%1" == "dirhtml" ( %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. goto end ) if "%1" == "singlehtml" ( %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. goto end ) if "%1" == "pickle" ( %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can process the pickle files. goto end ) if "%1" == "json" ( %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can process the JSON files. goto end ) if "%1" == "htmlhelp" ( %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can run HTML Help Workshop with the ^ .hhp project file in %BUILDDIR%/htmlhelp. goto end ) if "%1" == "qthelp" ( %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can run "qcollectiongenerator" with the ^ .qhcp project file in %BUILDDIR%/qthelp, like this: echo.^> qcollectiongenerator %BUILDDIR%\qthelp\click-log.qhcp echo.To view the help file: echo.^> assistant -collectionFile %BUILDDIR%\qthelp\click-log.ghc goto end ) if "%1" == "devhelp" ( %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp if errorlevel 1 exit /b 1 echo. echo.Build finished. goto end ) if "%1" == "epub" ( %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub if errorlevel 1 exit /b 1 echo. echo.Build finished. The epub file is in %BUILDDIR%/epub. goto end ) if "%1" == "epub3" ( %SPHINXBUILD% -b epub3 %ALLSPHINXOPTS% %BUILDDIR%/epub3 if errorlevel 1 exit /b 1 echo. echo.Build finished. The epub3 file is in %BUILDDIR%/epub3. goto end ) if "%1" == "latex" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex if errorlevel 1 exit /b 1 echo. echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. goto end ) if "%1" == "latexpdf" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex cd %BUILDDIR%/latex make all-pdf cd %~dp0 echo. echo.Build finished; the PDF files are in %BUILDDIR%/latex. goto end ) if "%1" == "latexpdfja" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex cd %BUILDDIR%/latex make all-pdf-ja cd %~dp0 echo. echo.Build finished; the PDF files are in %BUILDDIR%/latex. goto end ) if "%1" == "text" ( %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text if errorlevel 1 exit /b 1 echo. echo.Build finished. The text files are in %BUILDDIR%/text. goto end ) if "%1" == "man" ( %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man if errorlevel 1 exit /b 1 echo. echo.Build finished. The manual pages are in %BUILDDIR%/man. goto end ) if "%1" == "texinfo" ( %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo if errorlevel 1 exit /b 1 echo. echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. goto end ) if "%1" == "gettext" ( %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale if errorlevel 1 exit /b 1 echo. echo.Build finished. The message catalogs are in %BUILDDIR%/locale. goto end ) if "%1" == "changes" ( %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes if errorlevel 1 exit /b 1 echo. echo.The overview file is in %BUILDDIR%/changes. goto end ) if "%1" == "linkcheck" ( %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck if errorlevel 1 exit /b 1 echo. echo.Link check complete; look for any errors in the above output ^ or in %BUILDDIR%/linkcheck/output.txt. goto end ) if "%1" == "doctest" ( %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest if errorlevel 1 exit /b 1 echo. echo.Testing of doctests in the sources finished, look at the ^ results in %BUILDDIR%/doctest/output.txt. goto end ) if "%1" == "coverage" ( %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage if errorlevel 1 exit /b 1 echo. echo.Testing of coverage in the sources finished, look at the ^ results in %BUILDDIR%/coverage/python.txt. goto end ) if "%1" == "xml" ( %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml if errorlevel 1 exit /b 1 echo. echo.Build finished. The XML files are in %BUILDDIR%/xml. goto end ) if "%1" == "pseudoxml" ( %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml if errorlevel 1 exit /b 1 echo. echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. goto end ) if "%1" == "dummy" ( %SPHINXBUILD% -b dummy %ALLSPHINXOPTS% %BUILDDIR%/dummy if errorlevel 1 exit /b 1 echo. echo.Build finished. Dummy builder generates no files. goto end ) :end click-log-0.2.1/setup.cfg000066400000000000000000000001211316224213100151640ustar00rootroot00000000000000[wheel] universal = 1 [flake8] # W503: Line break before operator ignore = W503 click-log-0.2.1/setup.py000066400000000000000000000030341316224213100150630ustar00rootroot00000000000000#!/usr/bin/env python import ast import re from setuptools import setup _version_re = re.compile(r'__version__\s+=\s+(.*)') with open('click_log/__init__.py', 'rb') as f: version = str(ast.literal_eval(_version_re.search( f.read().decode('utf-8')).group(1))) setup( name='click-log', version=version, description='Logging integration for Click', author='Markus Unterwaditzer', author_email='markus@unterwaditzer.net', 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', ], ) click-log-0.2.1/tests/000077500000000000000000000000001316224213100145135ustar00rootroot00000000000000click-log-0.2.1/tests/test_basic.py000066400000000000000000000047361316224213100172170ustar00rootroot00000000000000# -*- coding: utf-8 -*- import logging import click from click.testing import CliRunner import click_log import pytest test_logger = logging.getLogger(__name__) click_log.basic_config(test_logger) test_logger.level = logging.INFO @pytest.fixture def runner(): return CliRunner() def test_basic(runner): @click.command() def cli(): test_logger.info('hey') test_logger.error('damn') result = runner.invoke(cli, catch_exceptions=False) assert not result.exception assert result.output == 'hey\nerror: damn\n' def test_multilines(runner): @click.command() def cli(): test_logger.warning(""" Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt""") result = runner.invoke(cli, catch_exceptions=False) assert not result.exception assert result.output == ( 'warning: \n' 'warning: Lorem ipsum dolor sit amet,\n' 'warning: consectetur adipiscing elit,\n' 'warning: sed do eiusmod tempor incididunt\n') def test_unicode(runner): @click.command() def cli(): test_logger.error(u""" ❤️ 💔 💌 💕 💞 💓 💗 💖 💘 💝 💟 💜 💛 💚 💙""") result = runner.invoke(cli, catch_exceptions=False) assert not result.exception assert result.output == ( 'error: \n' u'error: ❤️ 💔 💌 💕 💞 💓 💗 💖 💘\n' u'error: 💝 💟 💜 💛 💚 💙\n') def test_weird_types_log(runner): @click.command() def cli(): test_logger.error(42) test_logger.error('42') test_logger.error(b'42') test_logger.error(u'42') 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 click-log-0.2.1/tox.ini000066400000000000000000000001541316224213100146640ustar00rootroot00000000000000[testenv] passenv = LANG deps = pytest git+https://github.com/mitsuhiko/click commands = py.test []