Josh
03/11/2024, 2:11 PM<http://context.log.info|context.log.info>
inside of a software defined asset?Scout
03/11/2024, 2:11 PMget_dagster_logger()
utility function, which allows you to obtain a Dagster-managed logger that you can use to log messages. This function is particularly useful when you want to produce logs from within a custom resource in a way that is consistent with logging from within a software-defined asset using context.log
. Here's an example of how you might use get_dagster_logger()
within a custom resource: python from dagster import resource, get_dagster_logger @resource def my_custom_resource(_): log = get_dagster_logger() <http://log.info|log.info>("This is an info log from my custom resource") # ... rest of your resource implementation ...
When you use get_dagster_logger()
within a custom resource, the messages produced will be treated identically to messages created using context.log
within a software-defined asset. This means that they will be captured by Dagster and linked to the relevant computations, and they will appear in the Dagster UI if you are monitoring your runs there. Remember that the get_dagster_logger()
function is also useful when converting existing code into the Dagster framework, as it allows you to easily replace standard Python loggers with a Dagster-specific logger without needing to modify function signatures to pass around context.