Closed devforfu closed 5 years ago
Starting v1.0.15, you have a global WRITE_FN you can change (default print). Just type:
import fast_progress
fast_progress.fast_progress.WRITER_FN = {your func}
Let me know if this doesn't work.
this was my solution to this, thanks for the comment above this builds on that
it prints if the text needs to be overwritten and logs to file if its not an update to the progress bar.
import fastprogress
def log_fastai_msg(to_write, end=None):
"""log progress message from fastai"""
if end:
print(to_write, end=end)
else:
logging.info(to_write)
print(to_write)
# set fastprogress to write to log file
fastprogress.fastprogress.WRITER_FN = log_fastai_msg
It is not an issue per se, however, I wonder is it possible to modify
ConsoleProgressBar
class a bit to make possible to replaceprint
calls with something likeself.write
, and allow to insert your own writer?I know that Python allows you to redirect
stdin
with a special context manager but it would be more suitable for one to use custom output method. Because, for example, if you're using logging, you need to do the work twice, i.e., setup logger, and redirect stream. And if the progress bar could be configurable, then you could just pass logger instance inside or something.I mean, something like this (shouldn't be exactly this solution, of course):