-
-
Save tebeka/23b8524626e06227e340bf8c42b81877 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
class LoggingProxy: | |
"""Log attribute access to proxied object.""" | |
def __init__(self, obj): | |
self._obj = obj | |
def __getattribute__(self, attr): | |
val = getattr(self._obj, attr, None) | |
if val is None: | |
raise AttributeError(attr) | |
print(f'[DEBUG] {attr} -> {val!r}') | |
return val | |
now = LoggingProxy(datetime.now()) | |
print(now.year) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment