-
Notifications
You must be signed in to change notification settings - Fork 45.8k
feat(backend): setup logging utilities #10027
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
base: dev
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -115,6 +115,17 @@ Here are some common scenarios where you might use multiple Docker Compose comma | |
|
||
These scenarios demonstrate how to use Docker Compose commands in combination to manage your AutoGPT Platform effectively. | ||
|
||
### Logging | ||
The backend configures logging by calling `configure_logging()` at startup. | ||
Logs use the format: | ||
|
||
``` | ||
YYYY-MM-DD HH:MM:SS LEVEL [PREFIX] message {"json_fields": {...}} | ||
``` | ||
|
||
When creating loggers for user-facing modules, wrap them with | ||
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. what is a user-facing module? |
||
`TruncatedLogger(logging.getLogger(__name__), "[Component]")` to truncate long | ||
messages and include optional metadata. | ||
|
||
### Persisting Data | ||
|
||
|
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. why is this needed? |
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. why is this needed? |
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. why is this needed? |
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. why is this needed? |
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. why is this needed? |
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. put this in a 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. this script always exits normally, so it will never trigger CI or pre-commit check failure |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pathlib | ||
import re | ||
|
||
PATTERN = re.compile(r"logging\.getLogger\(") | ||
ROOT = pathlib.Path(__file__).resolve().parent / "backend" | ||
|
||
errors = [] | ||
|
||
for path in ROOT.rglob("*.py"): | ||
if path.name == "logging.py": | ||
continue | ||
text = path.read_text() | ||
if PATTERN.search(text) and "TruncatedLogger" not in text: | ||
errors.append(str(path.relative_to(ROOT))) | ||
|
||
if errors: | ||
print("Plain logging.getLogger usage detected in:\n" + "\n".join(errors)) | ||
Comment on lines
+13
to
+17
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. So any usage of But this PR doesn't fix all usages of If we needed system-wide logging truncation, add some middleware in But the last time we discussed this, there was no real need for this, because there are only a few specific places where messages with long "attachments" are being logged. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ def lint(): | |
["ruff", "format", "--diff", "--check", LIBS_DIR], | ||
["isort", "--diff", "--check", "--profile", "black", BACKEND_DIR], | ||
["black", "--diff", "--check", BACKEND_DIR], | ||
["python", "check_logging.py"], | ||
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. Add to format step too |
||
["pyright", *TARGET_DIRS], | ||
] | ||
lint_error = None | ||
|
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.