Skip to content

Add Log File Separation for Info and Error Levels#283

Closed
avirajsingh7 wants to merge 2 commits intomainfrom
enhancement/logs_segregation
Closed

Add Log File Separation for Info and Error Levels#283
avirajsingh7 wants to merge 2 commits intomainfrom
enhancement/logs_segregation

Conversation

@avirajsingh7
Copy link
Copy Markdown
Collaborator

@avirajsingh7 avirajsingh7 commented Jul 16, 2025

Summary

This PR enhances the logging system by introducing two separate rotating file handlers:

  • app.log for logs at level INFO and above.
  • error.log for logs at level ERROR and above.

Target issue is #234

Checklist

Before submitting a pull request, please ensure that you mark these task.

  • Ran fastapi run --reload app/main.py or docker compose up in the repository root and test.
  • If you've fixed a bug or added code that is tested and has test cases.

Summary by CodeRabbit

  • New Features
    • Error logs are now saved in a dedicated error log file, separate from general application logs, improving log organization and accessibility.
  • Chores
    • Updated logging configuration to enhance log management and clarity.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 16, 2025

Walkthrough

The logging setup was updated to introduce a separate rotating file handler for error logs, in addition to the existing application log and console handlers. Log file paths were split into distinct variables for general and error logs, and log levels for each handler were explicitly set.

Changes

File(s) Change Summary
backend/app/core/logger.py Added separate rotating file handler for error logs, split log file path variables, set handler levels.

Poem

Logs now split, both neat and clear,
Errors in one file, so troubles appear.
Info and above in the app log stay,
While error logs quietly squirrel away.
With each new hop, our logging grows bright—
Two files for the warren, all through the night!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2372555 and 854de69.

📒 Files selected for processing (1)
  • backend/app/core/logger.py (2 hunks)
🔇 Additional comments (4)
backend/app/core/logger.py (4)

10-11: LGTM: Clean separation of log file paths.

The introduction of separate constants for app and error log file paths follows good coding practices and makes the configuration more maintainable.


32-37: LGTM: Explicit stream handler configuration.

Making the log level explicit for the stream handler improves code clarity and maintainability.


39-46: LGTM: App log file handler configuration.

The app file handler is properly configured to capture INFO and above logs with appropriate rotation settings.


48-55: Double-logging of ERROR level logs
In backend/app/core/logger.py (lines 48–55), you’ve configured:

# === Error Log File Handler (ERROR and above) ===
error_file_handler = RotatingFileHandler(
    ERROR_LOG_FILE_PATH, maxBytes=10 * 1024 * 1024, backupCount=5
)
error_file_handler.setLevel(logging.ERROR)
error_file_handler.setFormatter(formatter)
error_file_handler.addFilter(CorrelationIdFilter())
logger.addHandler(error_file_handler)

Since your main app handler is set to INFO and above, ERROR-level entries will also be written to app.log, resulting in each ERROR being duplicated in both app.log and error.log. If that’s intentional, no changes are needed. Otherwise, to prevent duplication you could:

  • Restrict the app handler to INFO and WARNING only (e.g., set its level to WARNING or add a filter to exclude errors)
  • Or add a filter on the app handler to drop records with levelno >= logging.ERROR

Please confirm whether this duplication is desired or adjust the handler configuration accordingly.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@avirajsingh7 avirajsingh7 linked an issue Jul 16, 2025 that may be closed by this pull request
@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

Comment thread backend/app/core/logger.py
@avirajsingh7
Copy link
Copy Markdown
Collaborator Author

After investigating the logs setup, Vijay found that log streaming is already implemented, and everything is being sent to a single stream. Splitting logs by level (e.g., error/info) is turning out to be complex in ECS (sending only one stream of logs). This setup is much more straightforward on EC2, but not as flexible on ECS. Given the current limitations, we’ll need to Close this issue.
We will stick to sentry and current logging setup.

@AkhileshNegi AkhileshNegi deleted the enhancement/logs_segregation branch April 2, 2026 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request ready-for-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logs Segregation

2 participants