Stephen Bailey
08/03/2022, 1:09 PMget_dagster_logger
, which to my understanding allows us access to the same logger as context.log
, and I really like it. Feels like a more Pythonic way than context
to do logging in Dagster repo, while still getting value of seeing stuff in Dagit.
Are there any drawbacks to using it basically all over my repo (e.g. in resources, etc.)? Any reason I should prefer context
ever?
from dagster import op, get_dagster_logger
logger = get_dagster_logger()
@op
def foo_op():
<http://logger.info|logger.info>("running my op")
# vs
@op
def foo_op(context):
<http://context.log.info|context.log.info>("running my op")
owen
08/03/2022, 5:00 PMcontext.log()
.
To be overly pedantic, there's one slight difference based on the fact that the context
that is capturing these log messages will always be an op execution context. So if you use a resource within an op, and messages are logged within that resource, then the logged messages will not be tagged with the name of the resource (just the name of the op the resource is being used in), whereas they would be if you passed in context.log
into the resource instance from the @resource
decorator.
In most cases, this is pretty irrelevant, just thought I'd mention 🙂Stephen Bailey
08/03/2022, 5:13 PM