-
Notifications
You must be signed in to change notification settings - Fork 109
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
[logger] adds a ctx manager that restores effective level on exit #943
Conversation
I have thought some more about this. I think that |
I actually thought about that approach, but decided to include the getting the logger object bit, since otherwise I would need to pass the logger into the context manager and have more code to write at the usage point if I don't already have the logger. |
In the hypothesis2 branch, you use with scoped_logger('pymor.algorithms.gram_schmidt.gram_schmidt_biorth', level='FATAL'):
A1, A2 = gram_schmidt_biorth(U1, U2, copy=True) This would simply become with set_log_levels({'pymor.algorithms.gram_schmidt.gram_schmidt_biorth': 'FATAL'}):
A1, A2 = gram_schmidt_biorth(U1, U2, copy=True) So in this case, you actually have a few characters less. Using Do you have a concrete use case in mind, where you would actually want to use the logger returned by
|
Huh. If that's the only use you found I must've misremembered. |
|
My idea would be to modify |
Currently the user expectation for |
For me it would be obvious that the change is only temporary when |
I don't know what is the goal of this PR... There were mentions of the hypothesis branch. Is this something used only in the tests or also by users? |
This would be general user-facing. |
Ok. And what issue is this PR trying to fix? |
For me: temporarily/localized silencing an algorithms log output in a loop with restoring previous levels after the block. |
This reminds me of the context manager in |
@pmli, the question is whether to allow temporary setting of log levels via with set_log_levels({'pymor.models.iosys': 'WARN'}):
do_some_stuff() or if it would be better to use with set_log_levels_temporarily({'pymor.models.iosys': 'WARN'}):
do_some_stuff() as the user might think that the change is not temporary, even though the function is used in a |
I agree with René, using with log_levels({'pymor.models.iosys': 'WARN'}):
do_some_stuff() This then reads like English. |
I still dislike having two different functions for doing basically the same thing. @renefritze, @pmli, you are aware that f = open('foo', 'wt')
with f as g:
pass
f.write('bar') will give you an exception? Even Python builtins have such behavior. Or do you think this is a different situation? |
Also closing a file is not restoring its state to how it was before it was opened. So yes, very different situation. |
I agree with René again. As far as I see, |
With
I was meaning that the file object can be either used as a file object or as a context manager giving you a file object (itself). You must admit there is some similarity here. But I see the argument about global state and that a setter should return nothing. So let's go with a new |
So I'll merge as is and @sdrave makes an issue for the future to implement his idea? |
Ok. |
c0a1154
to
b3fc7dd
Compare
No description provided.