Open j-tr opened 1 year ago
@j-tr Would the PREFECT_LOGGING_EXTRA_LOGGERS
setting (documentation here) work for your use case?
i am not sure if an extra logger could capture this because the logs are not coming from any specific python library but they are just directly written to the stdout file descriptor.
@j-tr I'm not the right person to determine whether that's feasible or not, but what I can say is that many of our users collect logs at the infrastructure level through their log aggregator of choice. Doing so is probably the most robust way to ensure you are collecting all available logs.
@EmilRex, as discussed during our recent call, some follow-up information:
PREFECT_LOGGING_EXTRA_LOGGERS=isce
, unfortunately did not workAdding needs engineering feedback here as it would be great if someone could dig into what's possible here.
This issue is stale because it has been open 30 days with no activity. To keep this issue open remove stale label or comment.
Still relevant.
If we implement this as a setting i.e PREFECT_LOGGER_LOG_STOUT we'd also want to raise a warning. This setting should also be opt in.
@WillRaphaelson, that would work for us. Is this a feature you are potentially working on in the near future?
First check
Prefect Version
2.x
Describe the current behavior
When using third-party modules as black boxes in prefect tasks, certain log messages from these modules might be only displayed on the terminal of the machine that is running the flow but not sent to the Prefect cloud. This is because modules might not only use python print statements (that could be logged via log_prints=True) but also write directly to stdout or even run external subprocesses that are not even written in python.
Currently, there is no convenient way to forward these log messages to the prefect cloud without custom wrapper functions or instrumenting the third-party libraries with prefect logging.
Describe the proposed behavior
1) A general switch like log_prints (e.g. log_console_out) that would send everything that is visible on the terminal of the machine to the prefect cloud.
or
2) A util wrapper function that can take any python function and arguments, capture the output and send it to the cloud.
Example Use
The following script contains a task that executes a function that doesn't use conventional print statements but instead calls a .sh script that directly prints to the terminal. I tried to come up with two different wrapper functions that attempt to catch this output and send it to the logger.
redirect_stdout replaces stdout and stderr with a class that writes to the prefect logger on write(). This solves the problem for functions that write to sys.stdout but not for all outputs.
redirect_fd replaces the file descriptor of stdout with a tempfile and reads the content afterward. This works but is not concurrency safe as file descriptors are shared between subprocesses.
test.sh:
Output:
These lines from test.sh only end up in the prefect logger when redirecting the stdout file descriptor. Otherwise, they are just printed to the terminal.
Additional context
No response