-
Notifications
You must be signed in to change notification settings - Fork 16
iCtrl logging setup for files in application.Profile and general python files within the application directory #35
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
Changes from 3 commits
fa6f811
b692a39
4a48a1f
be67225
fea6f8f
5636256
c87deaa
224c592
f6abc97
bf0d837
05a3242
2e5ff20
b39aed1
99eeb04
fa66164
7d8efca
7c2d688
d959547
db38c86
8442aa9
29299ec
4b3beaa
6bd9c6a
1329d8f
ed567b1
4079546
f3da7d9
a63223c
bfdcb13
483df56
a0dafb1
eea19f0
3755e6a
6b1f640
7497ef7
9a3ab61
a799d1f
bcb03e0
5e0b6d2
b6c0756
55c57ca
edccf85
a86f91f
49d84fc
bc4f01f
dc31645
2d4a021
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |||||||||||||||
|
|
||||||||||||||||
| import base64 | ||||||||||||||||
| import json | ||||||||||||||||
| import logging | ||||||||||||||||
| import os | ||||||||||||||||
| import re | ||||||||||||||||
| import uuid | ||||||||||||||||
|
|
@@ -55,6 +56,9 @@ class ActivationType(IntEnum): | |||||||||||||||
| NORMAL_USER = 1 | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| logger = logging.getLogger(__name__) | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| class DBProfile(Profile): | ||||||||||||||||
|
|
||||||||||||||||
| def __init__(self, app): | ||||||||||||||||
|
|
@@ -67,13 +71,21 @@ def __init__(self, app): | |||||||||||||||
| self.salt = bcrypt.gensalt() | ||||||||||||||||
|
|
||||||||||||||||
| # key: user_id, value: activation code | ||||||||||||||||
| self.activation_cache = TTLCache(maxsize=1024, ttl=ACTIVATION_TTL_SECOND) | ||||||||||||||||
| size = 1024 | ||||||||||||||||
| self.activation_cache = TTLCache(maxsize=size, ttl=ACTIVATION_TTL_SECOND) | ||||||||||||||||
| logger.debug(f"activation_cache set up with {size}, expiration time = {ACTIVATION_TTL_SECOND}") | ||||||||||||||||
|
|
||||||||||||||||
| # key: user_id, value: True (to indicate the entry exists; can be any dummy value) | ||||||||||||||||
| self.resend_cooldown = TTLCache(maxsize=1024, ttl=RESEND_COOLDOWN_TTL_SECOND) | ||||||||||||||||
| self.resend_cooldown = TTLCache(maxsize=size, ttl=RESEND_COOLDOWN_TTL_SECOND) | ||||||||||||||||
| logger.debug(f"resend_cooldown cache set up with {size}, expiration time = {RESEND_COOLDOWN_TTL_SECOND}") | ||||||||||||||||
|
||||||||||||||||
| self.resend_cooldown = TTLCache(maxsize=size, ttl=RESEND_COOLDOWN_TTL_SECOND) | |
| logger.debug(f"resend_cooldown cache set up with {size}, expiration time = {RESEND_COOLDOWN_TTL_SECOND}") | |
| self.resend_cooldown = TTLCache(maxsize=size, ttl=RESEND_COOLDOWN_TTL_SECOND) | |
| logger.debug("resend_cooldown cache set up with %d, expiration time = %d", size, RESEND_COOLDOWN_TTL_SECOND) |
🧰 Tools
🪛 Ruff
80-80: Logging statement uses f-string
(G004)
li-ruihao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
li-ruihao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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.
🧹 Nitpick (assertive)
LGTM with a minor suggestion
The change in the method signature from logout() to logout(self) is correct and necessary for instance methods. The addition of the log message is also beneficial for tracking user logout events.
To address the static analysis hint (G004), consider using percent formatting for the logging statement:
-logger.info(f'Removed session user: {userid}')
+logger.info('Removed session user: %s', userid)This change will improve performance slightly as f-strings in logging statements are always evaluated, even if the log level is not met.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # remove the username from the session if it's there | |
| flask_session.pop('userid', None) | |
| userid = flask_session.pop('userid', None) | |
| logger.info(f'Removed session user: {userid}') | |
| # remove the username from the session if it's there | |
| userid = flask_session.pop('userid', None) | |
| logger.info('Removed session user: %s', userid) |
🧰 Tools
🪛 Ruff
211-211: Logging statement uses f-string
(G004)
Outdated
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.
🧹 Nitpick (assertive)
LGTM with a minor suggestion
The addition of this log message is valuable as it provides confirmation of successful user activation.
To address the static analysis hint (G004), consider using percent formatting for the logging statement:
-logger.info(f"Successfully activated user with userid={userid}")
+logger.info("Successfully activated user with userid=%s", userid)This change will improve performance slightly as f-strings in logging statements are always evaluated, even if the log level is not met.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| logger.info(f"Successfully activated user with userid={userid}") | |
| logger.info("Successfully activated user with userid=%s", userid) | |
🧰 Tools
🪛 Ruff
280-280: Logging statement uses f-string
(G004)
Outdated
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.
🧹 Nitpick (assertive)
LGTM with a minor suggestion
The addition of this log message is beneficial as it provides confirmation of successful user retrieval.
To address the static analysis hint (G004), consider using percent formatting for the logging statement:
-logger.info(f'Successfully retrieved user with userid={userid}')
+logger.info('Successfully retrieved user with userid=%s', userid)This change will improve performance slightly as f-strings in logging statements are always evaluated, even if the log level is not met.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| logger.info(f'Successfully retrieved user with userid={userid}') | |
| logger.info('Successfully retrieved user with userid=%s', userid) |
🧰 Tools
🪛 Ruff
295-295: Logging statement uses f-string
(G004)
Outdated
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.
🧹 Nitpick (assertive)
LGTM with a minor suggestion
The addition of this log message is valuable as it provides confirmation of successful session addition.
To address the static analysis hint (G004), consider using percent formatting for the logging statement:
-logger.info(f'Successfully added a new session: session_id = {session.id}')
+logger.info('Successfully added a new session: session_id = %s', session.id)This change will improve performance slightly as f-strings in logging statements are always evaluated, even if the log level is not met.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| logger.info(f'Successfully added a new session: session_id = {session.id}') | |
| logger.info('Successfully added a new session: session_id = %s', session.id) |
🧰 Tools
🪛 Ruff
321-321: Logging statement uses f-string
(G004)
li-ruihao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
li-ruihao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
li-ruihao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
li-ruihao marked this conversation as resolved.
Show resolved
Hide resolved
li-ruihao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
li-ruihao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
li-ruihao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
li-ruihao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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.
🧹 Nitpick (assertive)
LGTM with a minor suggestion
The addition of this log message is beneficial as it provides confirmation of successful activation email sending.
To address the static analysis hint (G004), consider using percent formatting for the logging statement:
-logger.info(f'Successfully sent out activation email to email={user.email}')
+logger.info('Successfully sent out activation email to email=%s', user.email)This change will improve performance slightly as f-strings in logging statements are always evaluated, even if the log level is not met.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| logger.info(f'Successfully sent out activation email to email={user.email}') | |
| logger.info('Successfully sent out activation email to email=%s', user.email) |
🧰 Tools
🪛 Ruff
450-450: Logging statement uses f-string
(G004)
Uh oh!
There was an error while loading. Please reload this page.