Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom colors #26

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion click_log/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ClickHandler(logging.Handler):
def emit(self, record):
try:
msg = self.format(record)
level = record.levelname.lower()
# level = record.levelname.lower()
Guts marked this conversation as resolved.
Show resolved Hide resolved
click.echo(msg, err=self._use_stderr)
except Exception:
self.handleError(record)
Expand Down
4 changes: 1 addition & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-

import sys
import os

import click_log
Expand Down Expand Up @@ -28,7 +27,6 @@
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:
Expand All @@ -37,7 +35,7 @@
'theme.')
print('-' * 74)

html_static_path = ['_static']
# html_static_path = ['_static']
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this file was changed either?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was the flake8 message for this? All of the variables here are "unused" in flake8's view

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's just a warning spotted by Sphinx during the build.

htmlhelp_basename = 'click-logdoc'

latex_elements = {}
Expand Down
54 changes: 49 additions & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ Click-log: Simple and beautiful logging for click applications

.. module:: click_log


.. contents:: Table of contents

----

Getting started
===============

Expand Down Expand Up @@ -83,20 +88,59 @@ The output will look like this::
error: Failed to divide by zero.


The ``error:``-prefix will be red, unless the output is piped to another
----

Customization
=============

Output colors
+++++++++++++

In the Getting started example, the ``error:`` prefix will be red, unless the output is piped to another
command.

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 ``setLevel`` on the given logger
accordingly.
Default colors:

+------------+---------+
| Log level | Color |
+============+=========+
| critical | red |
+------------+---------+
| debug | blue |
+------------+---------+
| error | red |
+------------+---------+
| exception | red |
+------------+---------+
| warning | yellow |
+------------+---------+

To customize colors used by each level of log, it's possible to pass a dict with the foreground color for each log level.
Color code must be `one of those included into click <https://github.com/pallets/click/blob/master/examples/colors/colors.py>`_

For example:

.. code-block:: python

import logging
import click_log

click_log.ColorFormatter.colors['info'] = dict(fg="bright_black")


Simple verbosity
++++++++++++++++

In the Getting started example, 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 ``setLevel`` on the given logger 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
===

Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@
install_requires=[
'click',
],
extras_require={
"doc": ["sphinx>=3.2,<3.3", "sphinx-rtd-theme>=0.5,<0.6"],
},
)