https://prefect.io logo
Title
d

Dev Dabke

11/16/2022, 4:28 PM
I have a very particular question: I have a central
logger
created as a singleton in a python module. However, sometimes, this module is invoked in a prefect flow. The logs from this logger are not displaying during the flow run, nor or they logging to orion. I am not invoking
get_run_logger
anywhere. The issue is that the module is only sometimes invoked in the context of a flow; it’s a shared library. Can I register prefect as a handle to this logger that will only log when in a prefect context?
m

Mason Menges

11/16/2022, 10:09 PM
Hey @Dev Dabke If I understand what you're asking correctly I think this might be what you're looking for https://discourse.prefect.io/t/how-to-add-extra-loggers-to-prefect-2-0/1040, though you could also check out this FAQ for logging as well that might help you find the information you're looking for https://discourse.prefect.io/t/prefect-logging-faq/1476
d

Dev Dabke

11/17/2022, 3:00 PM
lmao thanks! Let me see if that works. I was doing this before 🙈
# HACK: a disgusting hack to get logs to prefect.
if importlib.util.find_spec("prefect"):
    try:
        from prefect import (  # pylint: disable=import-outside-toplevel
            get_run_logger,
        )

        global logger
        logger = get_run_logger()  # pylint: disable=redefined-outer-name
    except:  # pylint: disable=bare-except
        pass