https://prefect.io logo
Title
j

justabill

02/03/2023, 1:17 AM
We just shipped Prefect 2.7.11 with expanded logging :wood: One of the best things about Prefect 2 is that not every function to be orchestrated. That flexibility is great, but users told us that even if they weren't orchestrating everything, they still wanted to be able to see logs in a single place. Now, Prefect defaults to displaying a warning instead of raising an error when you use Prefect loggers outside of flow or task runs. We've also added a setting
PREFECT_LOGGING_ORION_WHEN_MISSING_FLOW
to allow configuration of this behavior to silence the warning or raise an error as before. This means that you can attach Prefect's logging handler to existing loggers without breaking your workflows. Check it out:
from prefect import flow
import logging

my_logger = logging.getLogger("my-logger")
<http://my_logger.info|my_logger.info>("outside the flow")

@flow
def foo():
    <http://my_logger.info|my_logger.info>("inside the flow")

if __name__ == "__main__":
    foo()
You can even see messages from
my-logger
in the UI with
PREFECT_LOGGING_EXTRA_LOGGERS
:its-beautiful::
$ PREFECT_LOGGING_EXTRA_LOGGERS="my-logger" python example.py
example.py:6: UserWarning: Logger 'my-logger' attempted to send logs to Orion without a flow run id. The Orion log handler can only send logs within flow run contexts unless the flow run id is manually provided.
  <http://my_logger.info|my_logger.info>("outside the flow")
18:09:30.518 | INFO    | my-logger - outside the flow
18:09:31.028 | INFO    | prefect.engine - Created flow run 'elated-curassow' for flow 'foo'
18:09:31.104 | INFO    | my-logger - inside the flow
18:09:31.179 | INFO    | Flow run 'elated-curassow' - Finished in state Completed()
Collection updates: • prefect-shell got a new
ShellOperation
block that runs a shell operation • prefect-census got
CensusSync
block that runs a census sync Check out the release notes for information on the other enhancements and fixers in this release. Special thanks to Chia Berry, @Hans Lellelid, and Tomek for their contributions to this release! Happy Engineering! :marvin:
:marvin: 20
:party-parrot: 11
:gratitude-thank-you: 8
🙌 5
:blob-attention-gif: 4
😒quirtle_cool: 2
👍 6
🥳 9