Best practices thought/opinion -- I recently disco...
# dagster-feedback
s
Best practices thought/opinion -- I recently discovered
get_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?
Copy code
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")
🤔 1
👍 1
o
hi @Stephen Bailey! There's essentially zero difference between the two. The messages logged with get_dagster_logger() are captured and then processed by the same logger as
context.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 🙂
ty thankyou 1
1
s
very interesting!