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
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")
<|>("outside the flow")

def foo():
    <|>("inside the flow")

if __name__ == "__main__":
You can even see messages from
in the UI with
$ PREFECT_LOGGING_EXTRA_LOGGERS="my-logger" python 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.
  <|>("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
block that runs a shell operation • prefect-census got
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