-
-
Notifications
You must be signed in to change notification settings - Fork 580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use logging for warnings always, not just sometimes? #4812
Comments
Yeah we should probably try to be consistent. I’m not sure what best practice is here @martinjrobins @kratman ? FYI you can catch logger warnings, see https://docs.python.org/3/library/logging.html#logging.captureWarnings |
The answers here are quite good: https://stackoverflow.com/q/9595009 I think one way could be to use the logger warnings for solver-specific cases (which can be set to debug/info/warn/etc. by a user) via |
Based on the existence of a canonical answer that explains the reasons to do one or the other (https://docs.python.org/3/howto/logging.html as linked from the post raised by @agriyakhetarpal above), I think the answer to my OP is probably "no". But there could be a case for reviewing specific instances. It's admittedly relatively easy to deal with both types of warnings, once one knows that the library might generate them. |
Yes, I agree, @ejfdickinson.
One thing could be that we set up two separate loggers based on PyBaMM's modules, so that Another way could be to customise the singular logger to reflect what is being output from where better: so that |
PyBaMM sometimes raises warnings to its own logger using the
logging
package, viapybamm.logger.warning(...)
.PyBaMM also sometimes raises warnings using the native
warn()
functionality of thewarnings
package.Sometimes these are even in the same method -
pybamm.ParameterValues._create_from_bpx()
does both.Is there any reason why some warnings are logged, and some are not? I think it would be better to do one or the other, especially from the point-of-view of suppressing or explicitly handling warnings when interacting with PyBaMM from the outside.
The text was updated successfully, but these errors were encountered: