-
-
Save tebeka/a8d385fe06b9789c1c790329f1c4fb74 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 __getattr__(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