-
Notifications
You must be signed in to change notification settings - Fork 4
Python Logger Support: Complete Feature Set and Module Integration #103
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
Open
jaycedowell
wants to merge
28
commits into
logger
Choose a base branch
from
claude/lsl-python-logger-support-011CUtvLkFMeN9GaHsxVnpuW
base: logger
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Python Logger Support: Complete Feature Set and Module Integration #103
jaycedowell
wants to merge
28
commits into
logger
from
claude/lsl-python-logger-support-011CUtvLkFMeN9GaHsxVnpuW
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Convert verbose-controlled print statements to use LSL_LOGGER across multiple modules while maintaining backward compatibility. The pattern used is: - Print to console when verbose=True (backward compatible) - Always send to LSL_LOGGER (for GUI log capture) Modules converted: - lsl/imaging/selfcal.py: Self-calibration iteration progress and results - lsl/sim/vis.py: Beam model selection, JD setting, source visibility - lsl/sim/dp.py: Frame simulation progress for TBN/DRX - lsl/misc/scattering.py: Scattering deconvolution results - lsl/writer/uvfits.py: Stand ID mapping notifications - lsl/writer/fitsidi.py: Stand ID mapping notifications This complements the existing logger support in lsl.common.sdf and lsl.catalog, enabling error messages and status updates to be captured by GUI applications.
Replace % formatting and .format() calls with f-strings for improved readability in logger-enabled modules: - lsl/imaging/selfcal.py: Iteration progress messages - lsl/sim/vis.py: Beam model and array creation messages - lsl/sim/dp.py: Frame simulation progress messages - lsl/misc/scattering.py: Scattering results output - lsl/writer/uvfits.py: Stand mapping messages - lsl/writer/fitsidi.py: Stand mapping messages
Remove verbose parameter handling from selfcal module and convert all logging to DEBUG level. These messages (iteration progress, convergence metrics, final results) are primarily useful for debugging/development rather than normal operation. Changes: - Remove all 'if verbose:' checks and print() calls - Convert all logging from INFO/DEBUG to DEBUG only - Keep verbose parameter in signatures for backward compatibility - All messages now logged via LSL_LOGGER.debug() Users who want to see this output can enable DEBUG level logging.
The final calibration results (Best Gains, Best Delays, Best Phase Offsets) are actual output, not debug information. Changed from DEBUG to INFO level so they appear in normal logging. Iteration progress remains at DEBUG level.
Replace warnings.warn() with LSL_LOGGER.warning() for operational/runtime conditions rather than API deprecations: - lsl/sim/vis.py: Positional error notification during array creation - lsl/common/sdf.py: ASP filter degeneracy validation message - lsl/common/_sdf_utils.py: Timezone fallback search notification These are runtime operational messages, not code deprecation warnings, so they fit better with the logging system where users can control them via log levels. API usage warnings (like the STEPPED observation duration setter) remain as warnings.warn() since they indicate code that should be fixed.
Extends logger API with: - enable_console_logging/disable_console_logging for stdout/stderr output - enable_file_logging/disable_file_logging for file output - add_filter/remove_filter/clear_filters for pattern-based filtering
Complete NumPy-style documentation for all public functions: - set_log_level: Added Parameters section - get_log_level: Added Returns section - add_handler: Added Parameters section - remove_handler: Added Parameters section - capture_warnings: Added Parameters section
New features: - File logging: Start/stop logging to file with file dialog - Console output toggle: Enable/disable console logging via checkbox - Pattern filtering: Add/remove module pattern filters (e.g., 'lsl.imaging.*') - Buffer management: Auto-trim to 10,000 lines to prevent unbounded growth - Improved level control: Changes both logger level and display filtering - Better level mapping: Use proper dict mapping instead of arithmetic - Robust signal handling: Wrapped in try/except for cross-platform compatibility - Active filters display: Shows currently active filter patterns The GUI now leverages all the new logger.py API features including enable_console_logging(), enable_file_logging(), and add_filter().
- Added module-level docstring with integration examples showing: * Basic blocking GUI usage * Non-blocking threaded GUI usage * Using individual components - Enhanced LoggerGUI class docstring with features list and examples - Replaced trivial __main__ with interactive demo mode that: * Generates example log messages at all levels * Provides instructions for testing GUI features * Runs in background thread to demonstrate real-time updates This clarifies that logger_gui.py is meant to be imported into LSL scripts, not run standalone for production use.
test_logger.py (16 tests): - Test set/get log levels - Test ThreadedHandler queue integration - Test console logging enable/disable with optional level - Test file logging enable/disable with append/write modes - Test module pattern filtering (add/remove/clear) - Test filter functionality with actual log records - Test warning capture integration - Test handler add/remove with formatters test_logger_gui.py (11 tests): - Test LoggerFrame creation and display - Test buffer management with max_lines limit - Test clear buffer functionality - Test show_at_level filtering - Test FilterFrame level changes - Test console output toggle - Test pattern filter add/clear - Test complete LoggerGUI creation and messaging - All GUI tests skip gracefully when Tkinter unavailable or no display Both test files use unittest.skipIf decorators for headless CI compatibility. Tests verified locally with 100% pass rate (16 OK, 11 skipped in headless env).
When enable_file_logging() is called while already logging to a file, it now generates a RuntimeWarning before closing the existing file and switching to the new one. This prevents silent file switching that could confuse users. Also added test_file_logging_switch_warning to verify the warning is generated correctly (brings total logger tests to 17).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## logger #103 +/- ##
==========================================
+ Coverage 84.11% 84.25% +0.13%
==========================================
Files 92 93 +1
Lines 24443 24726 +283
==========================================
+ Hits 20561 20832 +271
- Misses 3882 3894 +12
🚀 New features to boost your workflow:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR completes the Python logging integration across LSL by:
1. Extending logging support to 6 additional modules with verbose output
2. Enhancing the logger API with console/file logging and filtering capabilities
3. Creating a full-featured Tkinter GUI for log monitoring
4. Improving code quality with f-string conversion and proper documentation
5. Converting runtime warnings to use the logging system
Core Logger API Enhancements (
lsl/logger.py)New Functions
enable_console_logging(level=None, stream=None)- Enable logging to stdout/stderr with optional level controldisable_console_logging()- Disable console outputenable_file_logging(filename, level=None, mode='a')- Enable logging to file with append/overwrite modesdisable_file_logging()- Close and disable file loggingadd_filter(pattern)- Add module pattern filters (e.g., 'lsl.imaging.*')remove_filter(pattern)- Remove specific filterclear_filters()- Remove all active filtersDocumentation Improvements
New Logger GUI Module (
lsl/logger_gui.py)A production-ready Tkinter GUI for real-time log monitoring with:
Features
Components
LoggerFrame- Display widget with auto-scrolling and level-based hidingFilterFrame- Control panel for all filtering/logging optionsLoggerGUI- Complete standalone GUI windowDocumentation
python -m lsl.logger_gui)Module Logging Extensions
Extended the logging pattern from
lsl.common.sdfto 6 additional modules:lsl/imaging/selfcal.pylsl/sim/vis.pylsl/sim/dp.pylsl/misc/scattering.pylsl/writer/uvfits.py&lsl/writer/fitsidi.pyAll modules follow the backward-compatible pattern:
Code Quality Improvements
String Formatting Modernization
Examples:
"Using %d-order" % deg → f"Using {deg}-order"
"Best Gains: %s" % tempGains → f"Best Gains: {tempGains}"
Runtime Warnings Conversion
Converted appropriate warnings.warn() calls to logging.warning():
lsl/sim/vis.py- Positional error warningslsl/common/sdf.py- ASP filter degeneracy warningslsl/common/_sdf_utils.py- Timezone search mode warningsRetained
warnings.warn()for API-level warnings (deprecation, usage issues).