-
-
Notifications
You must be signed in to change notification settings - Fork 424
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
Adds logger filter for TOKENS when logging in DEBUG MODE #539
base: master
Are you sure you want to change the base?
Changes from 1 commit
e0e20cd
f350642
103d28c
a77b392
577a085
54676d1
33d5bb5
6b8f87c
5a6e94a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ def __init__(self): | |
environment variable. | ||
""" | ||
super().__init__() | ||
self.mode = os.getenv('DEBUG_MODE_TOKEN_FILTER', 'DEFAULT').upper() | ||
self.mode = os.getenv('DEBUG_MODE_TOKEN_FILTER', 'DEFAULT').upper() | ||
|
||
def filter(self, record): | ||
""" | ||
|
@@ -37,7 +37,4 @@ def filter(self, record): | |
record.msg = re.sub(r'Bearer (\w+)', '[MASKED]', record.getMessage()) | ||
elif self.mode == "SUPPRESS": | ||
return False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe only suppress log messages which match the above regex? Otherwise this equivalent to disabling the logger entirely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am hoping a single space would suffice as a replacement? Or maybe just pass None to the msg? |
||
elif self.mode == "DEFAULT": | ||
msg = "Your logger, when in DEBUG mode, will log TOKENS" | ||
raise Warning(msg) | ||
return True | ||
return True # if mode is not MASKED then DEFAULT is implied |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest prefixing the envvar with the library name to reduce likelihood of collisions with other environment variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this comment. In fact I was running into this issue in another project. This project then variable name pattern is clean. I'm going to borrow and apply this pattern there as well. 🙏 Thank you!