Skip to content

Add comprehensive logging across application#53

Merged
sdglitched merged 1 commit intomainfrom
feat/logging
Aug 12, 2025
Merged

Add comprehensive logging across application#53
sdglitched merged 1 commit intomainfrom
feat/logging

Conversation

@sdglitched
Copy link
Owner

@sdglitched sdglitched commented Aug 12, 2025

Add comprehensive logging across application to improve monitoring, debugging, and operational visibility.

Fixes: #52

Summary by Sourcery

Add a centralized logging setup and integrate comprehensive info, success, warning, and error logs across routers, auth utilities, database setup, and CLI commands to improve monitoring, debugging, and operational visibility

New Features:

  • Introduce fastapi_ecom.utils.logging_setup module with stylized general, success, warning, and failure logging functions

Enhancements:

  • Instrument product, customer, business, and order routers as well as OAuth and basic auth flows with detailed logging around operations, errors, and outcomes
  • Add logging to database creation, Alembic migration commands, application startup, and root endpoint
  • Update CustomerView schema to make address fields optional

Build:

  • Bump Python requirement from 3.12 to 3.13 in pyproject.toml

@sdglitched sdglitched self-assigned this Aug 12, 2025
@sdglitched sdglitched added the enhancement New feature or request label Aug 12, 2025
@sourcery-ai
Copy link

sourcery-ai bot commented Aug 12, 2025

Reviewer's Guide

This PR integrates a centralized logging framework across the FastAPI application by importing a new logging_setup module and adding structured log statements (general, warning, success, failure) at key points in routers, authentication utilities, CLI commands, and database setup. It also introduces the logging_setup helper, adjusts customer schema fields to be optional, and bumps the Python requirement to 3.13.

Sequence diagram for logging in product creation

sequenceDiagram
    participant Business as actor Business User
    participant API as Product API
    participant DB as Database
    participant Log as logging_setup
    Business->>API: POST /product (add product)
    API->>Log: general("Adding product ...")
    API->>DB: Add product
    alt DB error
        API->>Log: failure("Product creation failed ...")
        API->>Business: HTTP 500
    else Success
        API->>Log: success("Product ... created successfully ...")
        API->>Business: Product created response
    end
Loading

Sequence diagram for logging in customer authentication (basic auth)

sequenceDiagram
    participant Customer as actor Customer
    participant API as Customer API
    participant DB as Database
    participant Log as logging_setup
    Customer->>API: Basic Auth login
    API->>DB: Query customer by email
    alt No customer found
        API->>Log: warning("No customer account found ...")
        API->>Customer: Authentication failed
    else Invalid password
        API->>Log: warning("Invalid password for customer ...")
        API->>Customer: Authentication failed
    else Success
        API->>Log: success("Customer authenticated via basic auth ...")
        API->>Customer: Authentication success
    end
Loading

Sequence diagram for logging in OAuth authentication

sequenceDiagram
    participant User as actor User
    participant API as OAuth API
    participant Log as logging_setup
    User->>API: OAuth login
    API->>Log: warning("Invalid OAuth token ...")
    API->>Log: success("OAuth token validated successfully ...")
    API->>Log: warning("OAuth token validation failed")
    API->>User: Auth result
Loading

Class diagram for the new logging_setup module

classDiagram
    class logging_setup {
        +success(message)
        +failure(message)
        +warning(message)
        +general(message)
        SUCCESS : str
        FAILURE : str
        WARNING : str
        GENERAL : str
        STDS : str
    }
Loading

Class diagram for updated CustomerView schema

classDiagram
    class CustomerView {
        email: EmailStr
        name: str
        addr_line_1: Optional[str]
        addr_line_2: Optional[str]
        city: Optional[str]
        state: Optional[str]
    }
Loading

File-Level Changes

Change Details Files
Integrated structured logging into API routers
  • Imported logging_setup in each router
  • Added general logs at endpoint entry
  • Logged warnings on not-found cases
  • Logged success on operations completion
  • Logged failures in exception handlers
fastapi_ecom/router/product.py
fastapi_ecom/router/customer.py
fastapi_ecom/router/business.py
fastapi_ecom/router/order.py
Enhanced authentication utilities with logging
  • Imported logging_setup in auth and OAuth modules
  • Logged warnings for token issues and invalid credentials
  • Logged success on successful authentications
  • Logged failures on auth errors
fastapi_ecom/utils/oauth.py
fastapi_ecom/utils/basic_auth.py
fastapi_ecom/utils/auth.py
Added logging to application setup and CLI commands
  • Logged database schema creation and Alembic stamping
  • Logged migration, upgrade, and downgrade operations
  • Logged server startup and root endpoint access
fastapi_ecom/main.py
fastapi_ecom/database/db_setup.py
fastapi_ecom/app.py
Introduced logging_setup helper module
  • Created success, failure, warning, and general functions
  • Styled log levels with click styles
fastapi_ecom/utils/logging_setup.py
Updated customer schema to accept optional address fields
  • Changed addr_line_1, addr_line_2, city, and state to Optional
fastapi_ecom/database/pydantic_schemas/customer.py
Bumped Python version dependency
  • Updated python requirement from ^3.12 to ^3.13
pyproject.toml

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @sdglitched - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

 - Implement structured logging throughout the application to improve monitoring, debugging, and operational visibility.

Signed-off-by: Shounak Dey <shounakdey@ymail.com>
@sdglitched sdglitched merged commit 86f272d into main Aug 12, 2025
4 checks passed
@sdglitched sdglitched deleted the feat/logging branch August 12, 2025 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add logging in the codebase

1 participant