linopy icon indicating copy to clipboard operation
linopy copied to clipboard

Better logging of print calls

Open lkstrp opened this issue 5 months ago • 1 comments

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 avatar Jul 28 '25 16:07 lkstrp

@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

FBumann avatar Sep 24 '25 20:09 FBumann