https://prefect.io logo
#prefect-community
Title
# prefect-community
j

John Ramey

10/20/2022, 5:05 PM
must
get_run_logger
be called in each task/flow? i have a flow with ~20 tasks. and after upgrading to Prefect 2, I have 20 different calls to
get_run_logger
β€” is there a better way to adhere to DRY?
βœ… 1
r

redsquare

10/20/2022, 5:38 PM
Agree, I am not a python pro but could the task or flow decorator not inject it into the func for use when specified in the params...or something
n

Nick DeCraene

10/20/2022, 6:41 PM
we added the env
PREFECT_LOGGING_EXTRA_LOGGERS=app
and it'll log those to the ui:
logger = logging.getLogger('app')
πŸ‘ 1
🦜 1
j

Jeff Hale

10/20/2022, 7:57 PM
Thank you @Nick DeCraene!
Added an issue to add this to the docs. https://github.com/PrefectHQ/prefect/issues/7274
n

Nick DeCraene

10/21/2022, 2:39 PM
So this worked for us locally, but when running on our hosted (v2.5) we get this error
Copy code
prefect.exceptions.MissingContextError: Logger 'job' 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.
@Jeff Hale any insight here?
j

Jeff Hale

10/21/2022, 2:48 PM
Hmm. I don’t know why that would be. @Zanie might know.
z

Zanie

10/21/2022, 2:59 PM
Sounds like the logger was used outside of a flow or task.
n

Nick DeCraene

10/21/2022, 3:33 PM
ah, so if it's not directly called in a task this will occur? Like a downstream method
z

Zanie

10/21/2022, 3:52 PM
Hm no it should be okay downstream. Just needs to be in the context.
n

Nick DeCraene

10/21/2022, 4:07 PM
hmm, so really the only way this could happen is if we log something on startup, before the flow begins. meaning we'd need to log something while all the modules are being imported
ah, it ended up being a log dependent on an env being present.... thanks for the help!
πŸ™Œ 1
24 Views