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,
Return the logger with the given name, or create one as needed.
This function calls
logging.getLoggerto find a logger with the specifiedname, or to create one.If the returned logger has no handlers attached already, a new
logging.StreamHandlerwill be created and attached based onstream.- Parameters:
- name
str The name of the logger.
- level
int,str, optional The level to set on the logger. If
level=None(default) is given, the logging level will be determined from theGWPY_LOG_LEVELenvironment variable, or set tologging.NOTSET.- stream
io.IOBase, optional The stream to write log messages to.
- fmt
str, optional The message format to use for a new handler.
- datefmt
str, optional The date format to use for a new handler.
- style
str, optional The type of
formatstring.- color
bool, optional If
True(default) try to usecoloredlogs.ColoredFormatteras the default formatter. IfFalsethe default formatter islogging.Formatter.
- name
- Returns:
- logger
logging.Logger A new, or existing,
Loggerinstance, with at least oneHandlerattached.
- logger
See also
logging.basicConfigFor more complete descriptions of some of the keyword arguments.
Notes
If
color=Trueis given (default) theterminal_supports_colors()function is called to determine whether the output terminal can support colours. If that returnsFalse, coloured formatting is not used.