Expand source code
# -*- coding: utf-8 -*-
import logging
from typing import Any
try:
import prefect
except ImportError:
pass
from prefeitura_rio.utils import assert_dependencies
@assert_dependencies(["prefect"], extras=["pipelines"])
def log(msg: Any, level: str = "info") -> None:
"""
Logs a message to prefect's logger.
"""
levels = {
"debug": logging.DEBUG,
"info": logging.INFO,
"warning": logging.WARNING,
"error": logging.ERROR,
"critical": logging.CRITICAL,
}
blank_spaces = 8 * " "
msg = blank_spaces + "----\n" + str(msg)
msg = "\n".join([blank_spaces + line for line in msg.split("\n")]) + "\n\n"
if level not in levels:
raise ValueError(f"Invalid log level: {level}")
prefect.context.logger.log(levels[level], msg) # pylint: disable=E1101