示例#1
0
def set_file_logger(config: ManimConfig, verbosity: str) -> None:
    """Add a file handler to manim logger.

    The path to the file is built using ``config.log_dir``.

    Parameters
    ----------
    config : :class:`ManimConfig`
        The global config, used to determine the log file path.

    verbosity : :class:`str`
        The verbosity level of the logger.

    Notes
    -----
    Calling this function changes the verbosity of all handlers assigned to
    manim logger.

    """
    # Note: The log file name will be
    # <name_of_animation_file>_<name_of_scene>.log, gotten from config.  So it
    # can differ from the real name of the scene.  <name_of_scene> would only
    # appear if scene name was provided when manim was called.
    scene_name_suffix = "".join(config["scene_names"])
    scene_file_name = os.path.basename(config["input_file"]).split(".")[0]
    log_file_name = (
        f"{scene_file_name}_{scene_name_suffix}.log"
        if scene_name_suffix
        else f"{scene_file_name}.log"
    )
    log_file_path = config.get_dir("log_dir") / log_file_name
    log_file_path.parent.mkdir(parents=True, exist_ok=True)

    file_handler = logging.FileHandler(log_file_path, mode="w")
    file_handler.setFormatter(JSONFormatter())

    logger = logging.getLogger("manim")
    logger.addHandler(file_handler)
    logger.info("Log file will be saved in %(logpath)s", {"logpath": log_file_path})

    config.verbosity = verbosity
    logger.setLevel(verbosity)
示例#2
0
def _config_test(last_frame: bool) -> ManimConfig:
    return ManimConfig().digest_file(
        str(
            Path(__file__).parent
            / (
                "config_graphical_tests_monoframe.cfg"
                if last_frame
                else "config_graphical_tests_multiframes.cfg"
            ),
        ),
    )