init_logger#

gwpy.log.init_logger(
name: str,
level: int | str | None = None,
*,
stream: IO = <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>,
fmt: str = '%(asctime)s:%(name)s:%(levelname)s:%(message)s',
datefmt: str | None = '%Y-%m-%dT%H:%M:%S%z',
style: str = '%',
color: bool = True,
) logging.Logger[source]#

Return the logger with the given name, or create one as needed.

This function calls logging.getLogger to find a logger with the specified name, or to create one.

If the returned logger has no handlers attached already, a new logging.StreamHandler will be created and attached based on stream.

Parameters:
namestr

The name of the logger.

levelint, str, optional

The level to set on the logger. If level=None (default) is given, the logging level will be determined from the GWPY_LOG_LEVEL environment variable, or set to logging.NOTSET.

streamio.IOBase, optional

The stream to write log messages to.

fmtstr, optional

The message format to use for a new handler.

datefmtstr, optional

The date format to use for a new handler.

stylestr, optional

The type of format string.

colorbool, optional

If True (default) try to use coloredlogs.ColoredFormatter as the default formatter. If False the default formatter is logging.Formatter.

Returns:
loggerlogging.Logger

A new, or existing, Logger instance, with at least one Handler attached.

See also

logging.basicConfig

For more complete descriptions of some of the keyword arguments.

Notes

If color=True is given (default) the terminal_supports_colors() function is called to determine whether the output terminal can support colours. If that returns False, coloured formatting is not used.