Hi, Is it possible to access a flow run's logs thr...
# ask-community
h
Hi, Is it possible to access a flow run's logs through prefect python code?
a
the easiest is when you trigger your flow from the CLI
Copy code
prefect run --id flow-uuid --watch
h
Thanks! let me try this..
k
Hey @Harish, are you trying to run this in a notebook? or through a Python script?
h
I was trying to access logs to a previous run, but the above command run a flow instead. Yes its run as a python code.
k
You can try hitting the GraphQL API with something like this for the flow run
Copy code
query {
	flow_run{
    logs {
      message
    }
  }
}
upvote 1
👀 1
h
I was also thinking of switching to writing logs to a file rather than logging in Prefect as it can only keep 2 weeks of history. Do you know if there is an easy to switch it in Prefect?
Thanks for the graphql snippet, will try that out
k
Check this for attaching a FileHandler
h
Nice! thanks