Hey all, I'm trying to read the logs of a step usi...
# ask-metaflow
m
Hey all, I'm trying to read the logs of a step using Python, this step had 2 attempts. Using the following I can access the log, BUT only for the second attempt. What I'm missing? Thanks 🙏
Copy code
for task in Step(f'{flow_name}/{run_id_}/{step_name}'):
    for log_line in task.loglines(stream="stdout"):
        log_text = log_line[1]
        print(log_text)
1
a
Task(
task_path_spec
, attempt=
attempt=0
).stdout will get you the stdout logs for the first attempt
m
what do you mean by
task_path_spec
?
a
{flow_name}/{run_id_}/{step_name}/{task_id}
m
Thats works, but if I run
Copy code
t = Task(f'{flow_name}/{run_id_}/{step_name}/{task_id}', attempt=0)
    for log_line in t.loglines(stream="stdout"):
        log_text = log_line[1]
        print(log_text)
or
Copy code
t = Task(f'{flow_name}/{run_id_}/{step_name}/{task_id}', attempt=1)
    for log_line in t.loglines(stream="stdout"):
        log_text = log_line[1]
        print(log_text)
I still get the logs for the first attempt insteaad of getting the logs for the second attempt when I use
attempt=1
a
do you see different output with
Task(f'{flow_name}/{run_id_}/{step_name}/{task_id}', attempt=1)
and
Task(f'{flow_name}/{run_id_}/{step_name}/{task_id}')
assuming the task only had 2 attempts
m
🤦‍♂️ my bad, I was overwritten the attempt in my code. That works thanks