hey <@U0667DNC02Y> can I write to dagster loggers ...
# ask-ai
c
hey @Scout can I write to dagster loggers without a direct reference to the context object?
s
Yes, you can write to Dagster loggers without a direct reference to the
context
object. We provide a utility function called
get_dagster_logger()
that allows you to get a Dagster-managed logger anywhere in your code. Here's how you can use it:
Copy code
python from dagster import get_dagster_logger  def my_logged_function():     log = get_dagster_logger()     for i in range(10):         <http://log.info|log.info>("Did %d things!", i+1)
Messages produced this way will be treated identically to messages created using
context.log
, resulting in a consistent logging experience. This feature is particularly useful when you’re converting existing code into the Dagster framework or when you want your logs to be captured by Dagster and linked to the relevant computations without modifying function signatures to pass around context. For more details, you can check out the documentation on [capturing Python logs](https://docs.dagster.io/concepts/logging/python-logging#capturing-python-logs).