Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 11, 2025

This PR adds a comprehensive default LOGGING configuration to the Django cookiecutter template, addressing the missing logging setup in generated projects.

Changes Made

LOGGING Configuration

Added a complete logging configuration to settings.py template with:

  • Formatters: Verbose format for development (DEBUG=True) and simple format for production
  • Handlers: Console handler that adapts formatter based on DEBUG setting
  • Loggers: Configured for Django framework, project-specific, and root logging
  • Environment Variables: Support for LOG_LEVEL and DJANGO_LOG_LEVEL configuration

Environment-Aware Configuration

The logging setup follows the template's existing patterns:

  • Uses python-decouple's config() for environment variable management
  • Defaults to INFO level logging
  • Automatically switches between verbose and simple formatters based on DEBUG setting

Example Generated Configuration

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "formatters": {
        "verbose": {
            "format": "{levelname} {asctime} {module} {process:d} {thread:d} {message}",
            "style": "{",
        },
        "simple": {
            "format": "{levelname} {message}",
            "style": "{",
        },
    },
    "handlers": {
        "console": {
            "class": "logging.StreamHandler",
            "formatter": "verbose" if DEBUG else "simple",
        },
    },
    "root": {
        "handlers": ["console"],
        "level": config("LOG_LEVEL", default="INFO"),
    },
    "loggers": {
        "django": {
            "handlers": ["console"],
            "level": config("DJANGO_LOG_LEVEL", default="INFO"),
            "propagate": False,
        },
        "myproject": {  # Uses actual project slug
            "handlers": ["console"], 
            "level": config("LOG_LEVEL", default="INFO"),
            "propagate": False,
        },
    },
}

Testing

  • Added comprehensive test suite in tests/test_logging.py
  • Tests cover default configuration, custom project slugs, formatter selection, and staticfiles interaction
  • All existing tests continue to pass
  • Manually verified logging functionality in generated Django projects

Benefits

  • Projects now have proper logging configured out-of-the-box
  • Environment variable configuration allows easy customization
  • Follows Django and template best practices
  • Compatible with all cookiecutter template options

Fixes #470.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • install.python-poetry.org
    • Triggering command: curl -sSL REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Default LOGGING config Add default LOGGING configuration to Django template Jul 11, 2025
Copilot AI requested a review from lucasrcezimbra July 11, 2025 01:11
Copilot finished work on behalf of lucasrcezimbra July 11, 2025 01:11
@lucasrcezimbra lucasrcezimbra marked this pull request as ready for review July 27, 2025 14:43
Copilot AI review requested due to automatic review settings July 27, 2025 14:43
@coderabbitai
Copy link

coderabbitai bot commented Jul 27, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 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? Join our Discord community 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 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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds comprehensive default logging configuration to the Django cookiecutter template to provide proper logging setup out-of-the-box for generated projects. The implementation follows the template's existing patterns using python-decouple for environment variable management and includes environment-aware formatter selection.

Key Changes

  • Added complete LOGGING configuration with formatters, handlers, and loggers to settings.py template
  • Implemented environment-based configuration using LOG_LEVEL and DJANGO_LOG_LEVEL variables
  • Created comprehensive test suite to validate logging configuration across different template options

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/settings.py Adds LOGGING configuration with verbose/simple formatters, console handler, and loggers for Django, project-specific, and root logging
tests/test_logging.py Adds test suite covering default configuration, custom project slugs, formatter selection, and staticfiles interaction
Comments suppressed due to low confidence (1)

Copilot AI requested a review from lucasrcezimbra July 27, 2025 14:52
Copilot finished work on behalf of lucasrcezimbra July 27, 2025 14:52
Copy link
Owner

@lucasrcezimbra lucasrcezimbra left a comment

Choose a reason for hiding this comment

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

You have to add "from pythonjsonlogger.json import JsonFormatter", also add the dependency to pyproject

Copy link
Contributor Author

Copilot AI commented Jul 27, 2025

You have to add "from pythonjsonlogger.json import JsonFormatter", also add the dependency to pyproject

Added JsonFormatter import from pythonjsonlogger.json and python-json-logger dependency to pyproject.toml. Updated structured formatter to use JsonFormatter class instead of manual JSON formatting. The structured formatter now provides proper JSON logging using the industry-standard library.

Copilot AI requested a review from lucasrcezimbra July 27, 2025 22:21
Copilot finished work on behalf of lucasrcezimbra July 27, 2025 22:21
psycopg = "3.2.9"
{%- endif %}
python-decouple = "3.8"
python-json-logger = "2.0.7"
Copy link
Owner

Choose a reason for hiding this comment

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

The latest version is 3.3.0

Suggested change
python-json-logger = "2.0.7"
python-json-logger = "3.3.0"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated python-json-logger to version 3.3.0. Commit: 0af9c35

},
"{{ cookiecutter.project_slug }}": {
"handlers": ["console"],
"level": config("LOG_LEVEL", default="INFO"),
Copy link
Owner

Choose a reason for hiding this comment

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

Do not duplicate the LOG_LEVEL access. Define a setting like this:

LOG_LEVEL = config(...

Then use it in all places

Suggested change
"level": config("LOG_LEVEL", default="INFO"),
"level": LOG_LEVEL,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Defined LOG_LEVEL as a setting variable once and now reusing it throughout the configuration instead of duplicating config() calls. Commit: 0af9c35

Copilot AI requested a review from lucasrcezimbra July 28, 2025 00:21
Copilot finished work on behalf of lucasrcezimbra July 28, 2025 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default LOGGING config

2 participants