https://dagster.io/ logo
#ask-community
Title
# ask-community
k

Kirill Yakunin

05/17/2023, 9:09 AM
Hello! Let's say, that I have a Dagster asset, which uses some function from some dependency. This function logs stuff using print(). Any nice way to capture this stdout output as Dagster Logs (without rewriting the dependency to accept context as argument and replacing print() with context.log.info()?
a

Anthony Carapetis

05/17/2023, 10:45 AM
1. Do you know about dagster's Compute Logs, which already captures stdout+stderr for each op? If not, check them out. 2. If compute logs aren't suitable and you really do want to redirect stdout to dagster event logs, you can use contextlib.redirect_stdout to redirect output to a file-like object. You could design such an object that calls
<http://context.log.info|context.log.info>
in its
write
method.
(you'd probably actually want a buffer and some logic to handle sending one message per line)