I have started working with PySiril to automate some processing via Python. I have been able to get the basic implementation running but I would like to be able to control the message output. I looked at the code but I can’t find a way to access the message logger to reduce the level and only see basic progress of the program. I would also like to redirect messages to a log file but not silence the command window. Anyone have an idea how to do this?
Hi,
there’s a Configure method for trace class.
So smthg like:
from pysiril.siril import Siril
app=Siril()
app.tr.Configure(0,1,1,1)
Should shut Info messages and keep only normal log, errors and warnings.
Now to redirect to both a log file and stdout, you can use a class like this one.
Then in your code, just redirect stdout to a Logger instance (and redirect back when it ends)
So smthg like:
saveout = sys.stdout
sys.stdout = Logger()
try:
#do smthg
except:
#catch exceptions
finally:
sys.stdout = saveout
should do what you want. There may be more elegant ways, this one has worked for me.
Cheers
C.
Thanks for the advice. I’ll give it a try.
GB