Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/colorlog/logging.py : 68%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Wrappers around the logging module."""
3from __future__ import absolute_import
5import functools
6import logging
8from colorlog.colorlog import ColoredFormatter
10BASIC_FORMAT = "%(log_color)s%(levelname)s%(reset)s:%(name)s:%(message)s"
13def basicConfig(**kwargs):
14 """Call ``logging.basicConfig`` and override the formatter it creates."""
15 logging.basicConfig(**kwargs)
16 logging._acquireLock()
17 try:
18 stream = logging.root.handlers[0]
19 stream.setFormatter(
20 ColoredFormatter(
21 fmt=kwargs.get('format', BASIC_FORMAT),
22 datefmt=kwargs.get('datefmt', None)))
23 finally:
24 logging._releaseLock()
27def ensure_configured(func):
28 """Modify a function to call ``basicConfig`` first if no handlers exist."""
29 @functools.wraps(func)
30 def wrapper(*args, **kwargs):
31 if len(logging.root.handlers) == 0:
32 basicConfig()
33 return func(*args, **kwargs)
34 return wrapper
37root = logging.root
38getLogger = logging.getLogger
39debug = ensure_configured(logging.debug)
40info = ensure_configured(logging.info)
41warning = ensure_configured(logging.warning)
42error = ensure_configured(logging.error)
43critical = ensure_configured(logging.critical)
44log = ensure_configured(logging.log)
45exception = ensure_configured(logging.exception)
47StreamHandler = logging.StreamHandler