Skip to content

Commit

Permalink
Fix black issue
Browse files Browse the repository at this point in the history
  • Loading branch information
taldcroft committed Feb 4, 2023
1 parent 7733521 commit 859e7b2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions ska_helpers/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
__all__ = ["basic_logger"]


def basic_logger(name, format="%(asctime)s %(funcName)s: %(message)s", **kwargs):
def basic_logger(
name, format="%(asctime)s %(funcName)s: %(message)s", propagate=False, **kwargs
):
"""Create logger ``name`` using logging.basicConfig.
This is a thin wrapper around logging.basicConfig, except:
Expand All @@ -16,14 +18,20 @@ def basic_logger(name, format="%(asctime)s %(funcName)s: %(message)s", **kwargs)
It will probably work but it is not guaranteed.
This function does nothing if the ``name`` logger already has handlers
configured, unless the keyword argument *force* is set to ``True``.
configured, unless the keyword argument ``force`` is set to ``True``.
It is a convenience method intended to do one-shot creation of a logger.
The default behaviour is to create a StreamHandler which writes to
``sys.stderr``, set a formatter using the format string ``"%(asctime)s
%(funcName)s: %(message)s"``, and add the handler to the ``name`` logger
with a level of WARNING.
By default the created logger will not propagate to parent loggers. This
is to prevent unexpected logging from other packages that set up a root
logger. To propagate to parent loggers, set ``propagate=True``. See
https://docs.python.org/3/howto/logging.html#logging-flow, in particular
how the log level of parent loggers is ignored in message handling.
Example::
# In __init__.py for a package or in any module
Expand Down Expand Up @@ -72,6 +80,7 @@ def basic_logger(name, format="%(asctime)s %(funcName)s: %(message)s", **kwargs)
:param name: str, logger name
:param format: str, format string for handler
:param propagate: bool, propagate to parent loggers (default=False)
:param **kwargs: other keyword arguments for logging.basicConfig
:returns: Logger object
"""
Expand All @@ -94,4 +103,6 @@ def basic_logger(name, format="%(asctime)s %(funcName)s: %(message)s", **kwargs)
finally:
logging.root = root

logger.propagate = propagate

return logger

0 comments on commit 859e7b2

Please sign in to comment.