I have a very particular question: I have a centra...
# prefect-community
d
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
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
lmao thanks! Let me see if that works. I was doing this before 🙈
Copy code
# 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