Thomas Hoeck
09/03/2020, 1:14 PMfrom prefect import task
import prefect
@task
def extract():
logger = prefect.context.get("logger")
logger.debug("Executing")
return [1,2,3]
extract.run()
as this yields
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-25-9ca06496a242> in <module>
11
12
---> 13 extract.run()
<ipython-input-25-9ca06496a242> in extract()
7 def extract():
8 logger = prefect.context.get("logger")
----> 9 logger.debug("Executing")
10 return [1,2,3]
11
AttributeError: 'NoneType' object has no attribute 'debug'
Dylan
09/03/2020, 2:10 PMprefect.context
and the logger
using MagicMock
or the likeThomas Hoeck
09/03/2020, 2:52 PMDylan
09/03/2020, 2:59 PMimport prefect
and call the logger directly inside your taskLogger
to replace the one provided by the prefect contextif prefect.context:
logger = prefect.context.get("logger")
else:
logger = LocalLogger()
run
function should work outside of a prefect contextIain Dillingham
09/04/2020, 9:13 AMget_logger
from prefect.utilities.logging
. I get the logger by calling that function rather than through the context object.get_logger
is also typed, so mypy doesn't complain.Thomas Hoeck
09/04/2020, 9:31 AMIain Dillingham
09/04/2020, 9:34 AMThomas Hoeck
09/04/2020, 9:39 AM