linopy
linopy copied to clipboard
Better logging of print calls
Describe the feature you'd like to see
There are a couple of print() calls in linopy. When a model is infeasible, pypsa-eur calls model.print_infeasibilities(), which calls print_labels(), which prints the infeasibilities to stdout, but not to the logs.
Would it theoretically be possible to replace all print() calls in linopy, with logger.info()?
@lkstrp About that, I think it would be nice to have a method that creates the str only. Im currently redirecting stdout to get the infos about the infeasibilities:
import io
from contextlib import redirect_stdout
f = io.StringIO()
# Redirect stdout to our buffer
with redirect_stdout(f):
model.print_infeasibilities()
documentation['infeasible_constraints'] = f.getvalue()
I would benefit from such a change