https://prefect.io logo
Title
d

DiffyBron

12/08/2019, 1:52 PM
how do you do flow.run(value=5) and only show the output instead of all the flow states?
j

Jenny

12/08/2019, 2:07 PM
Hello! Can you give a little more detail? What tasks are you running? When you say "show", do you mean in the logs? Thanks
d

DiffyBron

12/08/2019, 2:35 PM
Hello Jenny, I'm trying to run the following, and the output includes the flow logs, which i'm trying to omit when i run
python test.py
from prefect import Flow, Parameter, task
from prefect.tasks.control_flow import ifelse

@task
def check_if_even(value):
    return (value % 2 == 0)

@task
def print_even(value):
    print("{} is even".format(value))

@task
def print_odd(value):
    print("{} is even".format(value))


if __name__ == '__main__':
    with Flow("Check even or odd") as flow:
        value = Parameter("value")
        is_even = check_if_even(value)

        even = print_even(value)
        odd = print_odd(value)

        ifelse(is_even, even, odd)

     flow.run(value=5)
   
     flow.run(value=4)
My ideal output should be the following with TaskRunner logs omitted, what can i do to achieve that?
5 is even
4 is even
j

Jenny

12/08/2019, 2:47 PM
Let me know if you've any other questions!
Thanks for the extra info. You can change the default logging level using prefect.config.logging.level - there's more info on that here: https://docs.prefect.io/core/concepts/logging.html#logging-configuration
d

DiffyBron

12/08/2019, 3:07 PM
The default logger is INFO, and i totally want to filter it off. How can i do that? that link didn't seem to show us how to do that.
I'm seeing this
[2019-12-08 15:05:46,055] INFO - prefect.FlowRunner | Beginning Flow run for 'Check even or odd'
[2019-12-08 15:05:46,056] INFO - prefect.FlowRunner | Starting flow run.
[2019-12-08 15:05:46,062] INFO - prefect.TaskRunner | Task 'value': Starting task run...
[2019-12-08 15:05:46,064] INFO - prefect.TaskRunner | Task 'value': finished task run for task with final state: 'Success'
[2019-12-08 15:05:46,070] INFO - prefect.TaskRunner | Task 'check_if_even': Starting task run...
[2019-12-08 15:05:46,072] INFO - prefect.TaskRunner | Task 'check_if_even': finished task run for task with final state: 'Success'
[2019-12-08 15:05:46,078] INFO - prefect.TaskRunner | Task 'CompareValue: "False"': Starting task run...
[2019-12-08 15:05:46,080] INFO - prefect.TaskRunner | Task 'CompareValue: "False"': finished task run for task with final state: 'Success'
5 is even
j

Jeremiah

12/08/2019, 3:38 PM
Hi @DiffyBron, all Prefect log classes inherit from a prefect root logger, so you can configure the root logger individually by adding the following to the beginning of your script:
import logging
logging.getLogger("prefect").setLevel(0)
👍 1
This should result in the output:
d

DiffyBron

12/08/2019, 3:40 PM
Wow perfect Jeremiah! Thank you
j

Jeremiah

12/08/2019, 3:41 PM
No problem - the config setting @Jenny supplied should have the same effect (I’m just manually toggling the root setting), so I’ll check to see how we can better streamline that.
d

DiffyBron

12/08/2019, 3:45 PM
that's strange...i was trying to do the following. it didn't work. for me . so i asked again
import os 
os.environ['PREFECT__LOGGING__LEVEL'] = 'WARNING'
j

Jeremiah

12/08/2019, 3:47 PM
Though I haven’t tried setting
os.environ
directly, I’d expect that to work as long as you imported Prefect for the first time after that assignment
I’ll look into it
👍 1
c

Chris White

12/08/2019, 5:14 PM
My understanding of setting environment variables through the os module directly is that it only will have an effect on child sub processes
j

Jeremiah

12/08/2019, 5:15 PM
I agree, but I believe Core checks the presence of env vars in the
os.environ
dict, so I would have thought that subsequent imports would “work”
j

Jenny

12/08/2019, 5:21 PM
Thanks Jeremiah. DiffyBron -I think Jeremiah answered your question but if you want to set your config you can use a a user configuration file (<https://docs.prefect.io/core/concepts/configuration.html#environment-variables>) or set it as an environment variable
export PREFECT__LOGGING__LEVEL="WARNING"
should work.
d

DiffyBron

12/08/2019, 5:36 PM
Thanks Jenny, I've tried setting the environment variables within my IDE environment, and that worked too. Only thing that didn't work was the setting of environment variable with
os.environment
j

Jenny

12/08/2019, 6:03 PM
Thanks to Chris for his hint. I tried changing the os.environ before importing prefect and that seems to work:
👍 1
d

DiffyBron

12/09/2019, 3:16 AM
now that's interesting... it worked only when you put it at the top of the code just right after the import statement