I’m attempting to grab the logger out of the prefe...
# prefect-server
j
I’m attempting to grab the logger out of the prefect context. I am doing something similar to this
Copy code
@task()
def my_task():
    import prefect
    logger = prefect.context.get('logger')
I’ve tried it both with having the
import prefect
at the top level outside of the task and in the task like in that example and both times it gives me this
Copy code
TypeError: Pickling context objects is explicitly not supported. You should always access context as an attribute of the `prefect` module, as in `prefect.context`
Anyone have any ideas why it’s failing when i try to register the flow?
k
I think I’d need to see more of the flow here. Could you DM it to me?
j
Yeah
a
this error happens usually when you define the logger globally at the module scope rather than grabbing it from the context within a task
But this syntax is correct for Prefect 1.x
Copy code
@task()
def my_task():
    import prefect
    logger = prefect.context.get('logger')
    <http://logger.info|logger.info>("some info")
but you shouldn't e.g. return the logger and pass it to other tasks as data dependencies, this won't work
j
Gotcha. Yeah we are just using in the task and it’s only used / accessed from inside the task.
We are also using azure storage, idk if that has anything to do with it.
k
Storage should not