# ask-ai

Andrea Montes

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


03/08/2024, 8:05 PM
To create a logger that's captured by Dagster without modifying your
file, you can use the [
]( 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
. 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,
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
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]( in the Dagster documentation.