I'm having trouble with prefect logging with a log...
# ask-community
a
I'm having trouble with prefect logging with a loguru logger I've already set up.
Here's what I've got: 1. Built package as
mypackage
and installed in an environment 2.
mypackage_cli
flow serve runs the following flow to get a deployment with .serve 3. A basic structure of what’s going on is as follows:
src/mypackage/other/flow.py:
Copy code
from loguru import logger

from mypackage.other.module import function


@flow
def run_job() -> None:
    enable_prefect_loguru_support()
    ...
    logger.info("this logs correctly")
    function()
src/mypackage/other/module.py
Copy code
from loguru import logger

def function() -> None:
    logger.info("This doesn't show in prefect logs")
And
enable_prefect_loguru_support
comes from this post: Can I use loguru logs in Prefect flows? When running this setup, I use the following environment variables:
Copy code
PREFECT_LOGGING_EXTRA_LOGGERS=mypackage
PREFECT_LOGGING_MYPACKAGE_LEVEL=INFO
None of this gets the logs in the interior function to show up. Any ideas?
Got it resolved... the
loguru
logger wasn't enabled so the following helps, though is maybe less than ideal.
Copy code
def enable_prefect_loguru_support() -> None:
    # import here for distributed execution because loguru cannot be pickled.
    from loguru import logger

    logger.enable("mypackage")  # included this line
    run_logger = get_run_logger()
    ...
🙌 1
142 Views