Exemplo n.º 1
0
def configure() -> None:
    """
    Configure a molecule root logger.

    All other loggers will inherit the configuration we set here.
    """
    logger = logging.getLogger("molecule")
    handler = RichHandler(console=LOGGING_CONSOLE,
                          show_time=False,
                          show_path=False,
                          markup=True)  # type: ignore
    logger.addHandler(handler)
    logger.propagate = False
    logger.setLevel(logging.INFO)
Exemplo n.º 2
0
def configure() -> None:
    """
    Configure a molecule root logger.

    All other loggers will inherit the configuration we set here.
    """
    # Keep using root logger because we do want to process messages from other
    # libraries.
    logger = logging.getLogger()
    handler = RichHandler(console=console_stderr,
                          show_time=False,
                          show_path=False,
                          markup=True)  # type: ignore
    logger.addHandler(handler)
    logger.propagate = False
    logger.setLevel(logging.INFO)
Exemplo n.º 3
0
def get_logger(name=None) -> logging.Logger:
    """
    Build a logger with the given name and returns the logger.

    :param name: The name for the logger. This is usually the module
                 name, ``__name__``.
    :return: logger object
    """
    logger = logging.getLogger(name)  # type: logging.Logger
    logger.setLevel(logging.DEBUG)

    handler = RichHandler(console=LOGGING_CONSOLE,
                          show_time=False,
                          show_path=False,
                          markup=True)  # type: ignore
    logger.addHandler(handler)
    logger.propagate = False

    return logger
Exemplo n.º 4
0
def rich_logger_fixture() -> Tuple[logging.Logger, RichHandler]:
    """Returns tuple with logger and handler to be tested."""
    rich_handler = RichHandler(
        console=Console(
            file=io.StringIO(),
            force_terminal=True,
            width=80,
            color_system="truecolor",
            soft_wrap=True,
        ),
        enable_link_path=False,
    )

    logging.basicConfig(level="NOTSET",
                        format="%(message)s",
                        datefmt="[DATE]",
                        handlers=[rich_handler])
    rich_log = logging.getLogger("rich")
    rich_log.addHandler(rich_handler)
    return (rich_log, rich_handler)
Exemplo n.º 5
0
def bootstrap() -> Console:
    Markdown.elements["code_block"] = MyCodeBlock

    # We also initialize the logging console
    logging_console = Console(file=sys.stderr, force_terminal=1, theme=theme)

    logger = logging.getLogger()  # type: logging.Logger
    # logger.setLevel(logging.DEBUG)

    handler = RichHandler(console=logging_console,
                          show_time=False,
                          show_path=False,
                          markup=True)  # type: ignore
    # logger.addHandler(handler)
    logger.handlers = [handler]
    logger.propagate = False

    return Console(
        theme=theme,
        highlighter=rich.highlighter.ReprHighlighter(),
        record=True,
        soft_wrap=True,
        redirect=True,
    )
Exemplo n.º 6
0
    # verify that the long text was not wrapped
    output = strip_ansi_escape(
        rich_handler.console.file.getvalue())  # type: ignore
    assert text in output
    assert "ERROR" in output
    assert "\n" not in output[:-1]


if __name__ == "__main__":
    handler = RichHandler(
        console=Console(
            force_terminal=True,
            width=55510,  # this is expected to have no effect
            color_system="truecolor",
            soft_wrap=True,
        ),
        enable_link_path=False,
        show_time=True,
        show_level=True,
        show_path=True,
    )
    logging.basicConfig(
        level="NOTSET",
        format="%(message)s",
        # datefmt="[DATE]",
        handlers=[handler],
    )
    log = logging.getLogger("rich")
    # log.addHandler(handler)
    data = {"foo": "text", "bar": None, "number": 123}
    log.error("This was a long error")