https://dagster.io/ logo
#ask-ai
Title
# ask-ai
a

Andrea Montes

03/08/2024, 8:05 PM
@Scout can I use logger.info in functions outside dagster to see logging output in dagster webserver?
s

Scout

03/08/2024, 8:05 PM
To create a logger that's captured by Dagster without modifying your
dagster.yaml
file, you can use the [
get_dagster_logger
](https://docs.dagster.io/_apidocs/utilities#dagster.get_dagster_logger) utility function. This pattern is useful when logging from inside nested functions, or other cases where it would be inconvenient to thread through the context parameter to enable calls to
context.log
. Here's an example of how you can use `get_dagster_logger`:
Copy code
python from dagster import get_dagster_logger, graph, op  @op def ambitious_op():     my_logger = get_dagster_logger()     try:         x = 1 / 0         return x     except ZeroDivisionError:         my_logger.error("Couldn't divide by zero!")      return None
In this example,
my_logger
is a Python logger that will automatically be captured by Dagster. You can use this logger in functions outside of Dagster ops or graphs, and the logs will be captured and displayed in the Dagster webserver, assuming that the logger configuration is set up to capture these logs. Keep in mind that the logging module retains global state, meaning the logger returned by
get_dagster_logger
will be identical if called multiple times with the same arguments in the same process. This means that there may be unpredictable or unintuitive results if you set the level of the returned Python logger to different values in different parts of your code. For more detailed information on configuring Python log handlers and capturing logs in Dagster, you can refer to the [Python Logging section](https://docs.dagster.io/concepts/logging/python-logging) in the Dagster documentation.
4 Views