Add colored logs

This commit is contained in:
James R. Barlow
2020-04-15 00:05:38 -07:00
parent c2919f2e1c
commit f4f7946a0c
3 changed files with 19 additions and 1 deletions
+1
View File
@@ -2,6 +2,7 @@
# setup.py lists a separate set of requirements that are looser to simplify
# installation
cffi == 1.14.0
coloredlogs == 14.0 # technically optional
img2pdf == 0.3.3
pdfminer.six == 20200124
pikepdf == 1.10.2
+1
View File
@@ -97,6 +97,7 @@ setup(
install_requires=[
'chardet >= 3.0.4, < 4', # unlisted requirement of pdfminer.six 20181108
'cffi >= 1.9.1', # must be a setup and install requirement
'coloredlogs >= 14.0', # strictly optional
'img2pdf >= 0.3.0, < 0.4', # pure Python, so track HEAD closely
'pdfminer.six >= 20181108, <= 20200124',
'pikepdf >= 1.8.1, < 2',
+17 -1
View File
@@ -28,6 +28,11 @@ from ._sync import run_pipeline
from ._validation import check_options
from .cli import parser
try:
import coloredlogs
except ModuleNotFoundError:
coloredlogs = None
class Verbosity(IntEnum):
"""Verbosity level for configure_logging."""
@@ -92,7 +97,18 @@ def configure_logging(
else:
fmt = '%(levelname)7s -%(pageno)s %(message)s'
formatter = logging.Formatter(fmt=fmt)
use_colors = progress_bar_friendly
if not coloredlogs:
use_colors = False
if use_colors:
if os.name == 'nt':
use_colors = coloredlogs.enable_ansi_support()
if use_colors:
use_colors = coloredlogs.terminal_supports_colors()
if use_colors:
formatter = coloredlogs.ColoredFormatter(fmt=fmt)
else:
formatter = logging.Formatter(fmt=fmt)
console.setFormatter(formatter)
log.addHandler(console)