Skip to content

Conversation

@tomvothecoder
Copy link
Collaborator

@tomvothecoder tomvothecoder commented Nov 7, 2025

Description

Summary

This PR refactors xCDAT’s logging system to align with Python library best practices and ensure consistent, predictable log behavior across all modules.

It introduces a dedicated xcdat package logger, standardizes log formatting, prevents duplicate console output, removes intrusive global logging configuration, and ensures handler levels remain synchronized with the logger’s level.

Changes

  • Introduced _setup_xcdat_logger()

    • Creates a dedicated xcdat package logger (not the root logger).
    • Applies a uniform log format and configurable level.
    • Prevents duplicate handlers via force and conditional setup logic.
    • Disables propagation to avoid double logging.
    • Keeps all handler levels in sync with the logger level.
  • Updated __init__.py

    • Calls _setup_xcdat_logger() once on import to initialize a consistent logging configuration for all submodules.
  • Removed old root logger setup

    • Eliminated logging.basicConfig() and import-time handler creation.
    • Prevents duplicate console messages and interference with user logging configurations.
  • Dropped automatic warning capture

    • Removed logging.captureWarnings(True) to avoid modifying global warning handling.
    • Warning capture can now be enabled explicitly if needed.

Behavior Improvements

Aspect Before After
Logger type Root logger configured globally Dedicated xcdat logger
Duplicate console logs Yes No
Log format consistency Partial Uniform across all modules
Warning capture Always on (global side effect) Optional, explicit
Handler-level sync Possible mismatch Always consistent

Rationale

This refactor makes xCDAT’s logging:

  • Safe for use as a library — no modification of global logging state.
  • Consistent — all submodules share the same format, level, and handler.
  • Predictable — logger and handler levels always match.
  • Extensible — supports CLI or user-defined log configurations cleanly.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

If applicable:

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass with my changes (locally and CI/CD build)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have noted that this is a breaking change for a major release (fix or feature that would cause existing functionality to not work as expected)

@tomvothecoder tomvothecoder requested a review from Copilot November 7, 2025 18:53
@tomvothecoder tomvothecoder self-assigned this Nov 7, 2025
@tomvothecoder tomvothecoder added the type: bug Inconsistencies or issues which will cause an issue or problem for users or implementors. label Nov 7, 2025
@tomvothecoder tomvothecoder moved this from Todo to In Progress in xCDAT Development Nov 7, 2025
Copy link

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 refactors the logging configuration in xcdat by moving it from module-level initialization to a function-based approach. The changes improve code organization and provide better control over when logging is configured.

  • Converted logging constants to uppercase naming convention (log_formatLOG_FORMAT, added LOG_LEVEL)
  • Encapsulated logging setup logic in _setup_root_logger() function
  • Added warning capture functionality and improved documentation

Reviewed Changes

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

File Description
xcdat/_logger.py Refactored logging setup from module-level to function-based approach with _setup_root_logger(), updated constant naming to follow conventions, and added captureWarnings support
xcdat/init.py Added import and call to _setup_root_logger() to initialize logging when the package is imported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Nov 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (08a340a) to head (c0cec21).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #811   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           16        16           
  Lines         1784      1794   +10     
=========================================
+ Hits          1784      1794   +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tomvothecoder tomvothecoder requested a review from Copilot November 7, 2025 19:32
@tomvothecoder tomvothecoder marked this pull request as ready for review November 7, 2025 19:33
Copy link

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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tomvothecoder tomvothecoder changed the title Fix root logger config to prevent duplicate outputs Replace root logger instantiation with xcdat-based logger Nov 7, 2025
@tomvothecoder tomvothecoder requested a review from Copilot November 7, 2025 21:31
Copy link

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tomvothecoder tomvothecoder requested a review from Copilot November 7, 2025 21:40
Copy link

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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tomvothecoder tomvothecoder changed the title Replace root logger instantiation with xcdat-based logger Refactor xCDAT logging for consistency and safety Nov 7, 2025
@tomvothecoder tomvothecoder merged commit b7b27aa into main Nov 7, 2025
15 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in xCDAT Development Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Inconsistencies or issues which will cause an issue or problem for users or implementors.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants