https://dagster.io/ logo
Title
j

Jake Smart

08/31/2021, 10:50 PM
Is there any way to pass either the whole context object or the context logger into a resource?
c

Cameron Gallivan

08/31/2021, 10:56 PM
I think this is relevant, I do something like this when I want to log directly with the resource:
class S3Operations:
    """A class that builds on top of a pre-initialized S3 client to provide some higher level S3 operations."""
    def __init__(self, s3_client, logger=None):
        self.client = s3_client
        self.logger = logger
    
    def echo(self, msg):
        if self.logger is not None:
            <http://self.logger.info|self.logger.info>(msg)

@resource(required_resource_keys={'s3'})
def s3_operations(init_context: InitResourceContext):
    """Exposes S3Operations as a dagster resource and initializes with the s3_client connect resource."""
    return S3Operations(init_context.resources.s3, init_context.log)
j

Jake Smart

08/31/2021, 10:58 PM
oh i like that. I think that will work for me
thanks!
👍 1