-
Notifications
You must be signed in to change notification settings - Fork 3
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
ENH: add logging proprety machine #2
base: master
Are you sure you want to change the base?
Conversation
Add a sub-class of PropertyMachine which takes an optional logging in `__init__` which is used to log all state changes at the INFO level.
Logging is nice feature, so 👍 for the idea, but why would somebody create such property explicitly in business logic layer if he/she would like to have logging? My suggestion is to forget about This way anybody could enable/disable logging if needed without thinking in advance just by configuring logging handlers and without any change in business logic objects. |
The logic for having a sub-class that implements the logging framework is to avoid having to pay the (minor) performance cost if you do not want the logging. |
Well @tacaswell I was thinking about this a bit, performance reason is not enough for me. Logging is important but I don't want to change implementation in order to enable/disable logs from my app (which is using this library) especially that this is not 'the way' suggested in the docs. |
I'm open for discussion, but this solution is too dirty. |
https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library (docs for current python) That mostly talks about not registering default handlers on to your library and how to avoid having your library annoy users if they are not using logging. I don't see anything that is for or against this usage. Part of my thinking here is that users are going to integrate ssm into another library which is using logging and may have multiple state machines. As implemented it allows the client library to inject into ssm where to log messages to on a pre-machine basis. If |
It's the same anyway ;)
Yes, but the approach is different. I could stay with 'this is how its done', but more arguments for this at the end.
Assuming we will do logging always as suggested in docs (
Isn't that the point of logging?
Why this isn't more clear more below. About logging per-instance: I've never seen anything like that. Furthermore I find it totally useless:
At last, few words why this solution isn't clear: you are repeating yourself. Simple state machines are... simple! It's easy to make two implementations without repeating logic here, because you can use inheritance like in your PR. Now think how would you make two versions of each object - one with logging, and second without. What if ssm will grow (and I intend it to ;) )? What if each function will as big as this init -> https://github.com/kivy/kivy/blob/master/kivy/input/providers/linuxwacom.py#L138 ? This would be extremely hard to maintain such code. KISS and DRY rules apply here. :) That's why I think we should stick with standard option where logging is always given, but in case of lib disabled by default. And with this some help would be definitely appreciated. P.S. You could take a look on kivy project and the way they are using logging - it's definitely worth seeing. |
Add a sub-class of PropertyMachine which takes an optional logging in
__init__
which is used to log all state changes at the INFO level.If this of interest to you to include in main line I will add tests + docs + make level configurable.