sk4la
12/20/2020, 7:24 PM# Prefect example
import logging
import prefect
@task
def call_a_foreign_function():
log_from_a_foreign_function()
def log_from_a_foreign_function():
logger = prefect.context.get("logger", logging.getLogger("default_logger_if_no_prefect_context_is_found"))
<http://logger.info|logger.info>("It works! I can still log to the main logger even if I'm a foreign function!")
I tried to do something like this in order to do the equivalent within Dagster:
# Dagster equivalent
import logging
from dagster import solid
@solid
def call_a_foreign_function():
log_from_a_foreign_function()
def log_from_a_foreign_function():
logging.getLoggerClass()("dagster").warning("Can I speak to the UI like this?")
logging.getLogger("dagster").warning("Can I speak to the UI like this?")
Sadly, it does not seem to work, I’m only able to log to the Dagit console (not the UI).
Does Dagster have a cool way to log to the UI from “outside” of solids ?daniel
12/20/2020, 7:28 PMsk4la
12/20/2020, 7:33 PMcontext.log
object to every foreign function, is there another way to “retrieve the logger from the other side” ?daniel
12/20/2020, 7:58 PMsk4la
12/20/2020, 8:00 PMNoah K
12/21/2020, 12:10 AMmax
12/21/2020, 7:25 PMimport logging
and log that waylogging
) that will show up in dagit, just not in the structured log viewerprint
statements etc.sk4la
01/12/2021, 7:43 PMlogging
module). The main benefit I see (based on my own experience) is the ability to “catch” the logger from ouside of Dagster without the need to pass around the context object.