-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add log_prints
option to redirect print to logs
#7580
Conversation
✅ Deploy Preview for prefect-orion ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Needs:
|
Nate is leading tests for this. |
works 🎉 from prefect import flow
@flow(log_prints=True)
def hello():
print("Greetings from Prefect! 🤗")
if __name__ == "__main__":
hello() from prefect import flow, task
@task(log_prints=True)
def print_sth_nice():
print("This is nice")
@flow(log_prints=True)
def hello():
print("Greetings from Prefect! 🤗")
print_sth_nice()
if __name__ == "__main__":
hello() from prefect import flow, task
@task
def print_sth_nice():
print("This is nice")
@flow
def hello():
print("Greetings from Prefect! 🤗")
print_sth_nice()
if __name__ == "__main__":
hello() from prefect import flow, task
@task(log_prints=False)
def print_sth_nice():
print("This is nice")
@flow(log_prints=True)
def hello():
print("Greetings from Prefect! 🤗")
print_sth_nice()
if __name__ == "__main__":
hello() |
Co-authored-by: Will Raphaelson <[email protected]> Co-authored-by: Michael Adkins <[email protected]>
…st_log_prints.py` (#7587)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QA passes
@@ -807,6 +816,11 @@ def task( | |||
result_serializer: An optional serializer to use to serialize the result of this | |||
task for persistence. Defaults to the value set in the flow the task is | |||
called in. | |||
timeout_seconds: An optional number of seconds indicating a maximum runtime for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! The only thing is possibly a test explicitly for checking that the default behavior is False
?
Also, TIL about the builtins
module. I'd always thought "builtins" was just a colloquialism.
Co-authored-by: Nathan Nowack <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Only reviewed docs and docstrings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it!
Co-authored-by: Terrence Dorsey <[email protected]>
Thanks for the help everyone! |
Co-authored-by: Will Raphaelson <[email protected]> Co-authored-by: Will Raphaelson <[email protected]> Co-authored-by: Nathan Nowack <[email protected]> Co-authored-by: Terrence Dorsey <[email protected]>
Co-authored-by: Will Raphaelson <[email protected]> Co-authored-by: Will Raphaelson <[email protected]> Co-authored-by: Nathan Nowack <[email protected]> Co-authored-by: Terrence Dorsey <[email protected]>
Addresses the much requested
log_stdout
feature from v1 in v2 by adding alog_prints
option. It is very hard for us to log standard output from within the run as we have no way to tell where the bytes are coming from (i.e. you cannot disable capturing per task or flow). We can, however, patch the builtinprint
method, allowing us to identify the flow or task run the message comes from.This pull request introduces temporary patching of
print
to accomplish logging of prints from within tasks or flows. This will also apply to any functions within the scope of a task or a flow e.g. if they call into another library. If a flow or task run context is not present, we will justprint
as normal.There are options at the flow, task, and settings level. Defaults for children (subflows and tasks) are pulled from the parent flow.
Closes #7117
Example
Play with the following, try
None
,False
andTrue
for values:Checklist
<link to issue>
"fix
,feature
,enhancement
Future work
We may add a
log_stdout
feature but it would operate at the infrastructure level where we actually have access to the full standard output stream.