Skip to content

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

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

Swiftyos
Copy link
Contributor

Summary

  • initialize backend logging in entry point scripts
  • document log format and logger usage
  • add pre-commit hook to warn on plain logger instantiation

Testing

  • poetry -C autogpt_platform/backend run format
  • poetry -C autogpt_platform/backend run lint
  • poetry -C autogpt_platform/backend run test (fails: Error 111 connecting to localhost:6379)

@Swiftyos Swiftyos requested a review from a team as a code owner May 23, 2025 20:04
@Swiftyos Swiftyos requested review from ntindle and removed request for a team May 23, 2025 20:04
@Swiftyos Swiftyos requested a review from Pwuts May 23, 2025 20:04
@Swiftyos Swiftyos added the codex label May 23, 2025
@github-project-automation github-project-automation bot moved this to 🆕 Needs initial review in AutoGPT development kanban May 23, 2025
Copy link

netlify bot commented May 23, 2025

Deploy Preview for auto-gpt-docs-dev canceled.

Name Link
🔨 Latest commit defc851
🔍 Latest deploy log https://app.netlify.com/projects/auto-gpt-docs-dev/deploys/6830d4bd12113700088475bd

@github-actions github-actions bot added the platform/backend AutoGPT Platform - Back end label May 23, 2025
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Error Handling

The script detects plain logger usage but only prints errors without returning a non-zero exit code, which means the pre-commit hook might not properly fail when violations are found.

if errors:
    print("Plain logging.getLogger usage detected in:\n" + "\n".join(errors))
Missing Documentation

The TruncatedLogger is used but there's no docstring explaining its purpose or how it differs from a standard logger in the visible code.

logger = TruncatedLogger(logging.getLogger(__name__), "[App]")

Copy link

netlify bot commented May 23, 2025

Deploy Preview for auto-gpt-docs canceled.

Name Link
🔨 Latest commit defc851
🔍 Latest deploy log https://app.netlify.com/projects/auto-gpt-docs/deploys/6830d4bd030a7100080771f0

Copy link

deepsource-io bot commented May 23, 2025

Here's the code health analysis summary for commits dc981b5..defc851. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource JavaScript LogoJavaScript✅ SuccessView Check ↗
DeepSource Python LogoPython✅ Success
🎯 1 occurence resolved
View Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

@@ -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"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add to format step too

@Swiftyos Swiftyos marked this pull request as draft May 23, 2025 20:57
@github-actions github-actions bot added the conflicts Automatically applied to PRs with merge conflicts label Jun 4, 2025
Copy link
Contributor

github-actions bot commented Jun 4, 2025

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

Copy link
Member

@Pwuts Pwuts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What specific issue(s) does this PR aim to solve?

Code needs some work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put this in a scripts folder

Comment on lines +13 to +17
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So any usage of logger.getLogger not wrapped in TruncatedLogger is now reported as a linting error?

But this PR doesn't fix all usages of logging.getLogger so the PR wouldn't pass this check.

If we needed system-wide logging truncation, add some middleware in configure_logging to do this rather than wrapping all uses across the codebase in a helper class.

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.

Copy link
Member

Choose a reason for hiding this comment

The 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

- repo: local
hooks:
- id: check-loggers
name: Check for plain loggers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: Check for plain loggers
name: Check for plain loggers - AutoGPT Platform - Backend

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

YYYY-MM-DD HH:MM:SS LEVEL [PREFIX] message {"json_fields": {...}}
```

When creating loggers for user-facing modules, wrap them with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is a user-facing module?

@github-project-automation github-project-automation bot moved this from 🆕 Needs initial review to 🚧 Needs work in AutoGPT development kanban Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codex conflicts Automatically applied to PRs with merge conflicts platform/backend AutoGPT Platform - Back end Review effort 2/5 size/m
Projects
Status: 🚧 Needs work
Development

Successfully merging this pull request may close these issues.

3 participants