Skip to content

feat: Add comprehensive logging system with VERBOSE level#32

Open
poiley wants to merge 2 commits into
mainfrom
feat/comprehensive-logging
Open

feat: Add comprehensive logging system with VERBOSE level#32
poiley wants to merge 2 commits into
mainfrom
feat/comprehensive-logging

Conversation

@poiley

@poiley poiley commented Aug 21, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR implements a comprehensive logging system with improved CLI architecture, structured logging, and the new VERBOSE log level for detailed API tracking.

Related Issue: #35

🎯 Major Features

Comprehensive Logging System

  • Centralized logging module (logging_config.py) with JSON formatting
  • Five log levels: ERROR, WARNING, INFO, VERBOSE, DEBUG
  • Multiple log types: main, API, analysis, debug with automatic rotation
  • Automatic log directory setup at ~/.rulectl/logs/

Enhanced CLI Architecture (BREAKING CHANGES)

  • NEW: Direct rulectl logs command (replaces rulectl config logs)
  • Intuitive command structure following industry standards (docker logs, kubectl logs)
  • Clean separation: config=settings, logs=output, start=execution

VERBOSE Log Level

  • Perfect balance: API details without debug noise
  • Tracks: API calls, token usage, rate limiting, request patterns
  • Level 15: Between INFO (20) and DEBUG (10)
  • Replaces --verbose-logging flag with cleaner log level system

Comprehensive Test Suite

  • 58 test cases covering all logging functionality
  • Core tests: Log levels, JSON formatting, structured logging
  • CLI tests: Options, commands, error handling, integration
  • API tests: Rate limiter, token tracker, performance monitoring
  • Test runner and complete documentation

🔧 New CLI Commands

Log Viewing (NEW Direct Command)

rulectl logs                          # Show recent main logs
rulectl logs --type api               # Show API logs  
rulectl logs --type analysis          # Show analysis summaries
rulectl logs --type debug             # Show debug information
rulectl logs --follow                 # Follow logs in real-time
rulectl logs --lines 100              # Show more lines

Log Configuration (Enhanced)

rulectl start --log-level VERBOSE     # API tracking level
rulectl start --log-level DEBUG       # Full debug level
rulectl start --log-dir ./logs        # Custom log location

📊 Enhanced API Monitoring

  • Detailed API call tracking with timing and success/failure logging
  • Rate limiting event logging with backoff strategies and delays
  • Token usage monitoring with cost calculations per analysis phase
  • Structured JSON logs for easy parsing and analysis

🗂️ Log Organization

  • Main Log: ~/.rulectl/logs/rulectl.log - General application events
  • API Log: ~/.rulectl/logs/api-calls-YYYY-MM.log - Detailed API tracking
  • Analysis Log: ~/.rulectl/logs/analysis-YYYY-MM-DD.log - Daily summaries
  • Debug Log: ~/.rulectl/logs/debug.log - Technical debugging (JSON)

🚨 Breaking Changes

CLI Command Changes

# Old (no longer works)
rulectl config logs --log-type api --follow

# New (required)
rulectl logs --type api --follow

Removed Options

  • --verbose-logging flag (replaced by --log-level VERBOSE)
  • rulectl config logs (moved to direct rulectl logs)

Migration Guide

  • rulectl config logsrulectl logs
  • --log-type--type
  • --verbose-logging--log-level VERBOSE

💡 Benefits

  • 🔍 Full transparency: Complete visibility into rulectl operations
  • 💰 Cost monitoring: Real-time API usage and expense tracking
  • 🛠️ Easy debugging: Structured logs make troubleshooting simple
  • 📊 Performance insights: Identify bottlenecks and optimization opportunities
  • 🏗️ Better architecture: Intuitive CLI following industry standards
  • 📝 Audit trail: Complete record of all analysis runs

📚 Documentation

  • Complete logging guide in LOGGING.md
  • Updated README with all new features and examples
  • CLI help integration with clear option descriptions
  • Comprehensive test documentation in tests/README.md
  • Usage examples for common monitoring scenarios

🧪 Test Coverage

# Run all tests
python tests/run_logging_tests.py

# Run with pytest
pip install -r tests/test_requirements.txt
pytest tests/ -v

Test Results: 58 comprehensive test cases covering:

  • ✅ Core logging functionality (VERBOSE level, JSON formatting)
  • ✅ CLI integration (new commands, options, error handling)
  • ✅ API monitoring (rate limiter, token tracker, performance)
  • ✅ Real integration with actual CLI commands

Performance

  • Efficient structured logging with minimal overhead
  • Log rotation prevents disk space issues
  • Conditional logging avoids unnecessary processing
  • JSON format enables fast parsing and analysis

This implementation provides production-ready observability for rulectl with an intuitive CLI architecture that follows established patterns while maintaining comprehensive functionality.

🤖 Generated with Claude Code

@poiley

poiley commented Aug 21, 2025

Copy link
Copy Markdown
Contributor Author

I recommended merging the following PRs, rebasing this branch, and moving documentation to docs/ before merging this PR.

@poiley
poiley requested a review from etbyrd August 21, 2025 03:19
@poiley
poiley force-pushed the feat/comprehensive-logging branch 2 times, most recently from e3d4a24 to f76bb41 Compare September 2, 2025 21:39
poiley and others added 2 commits September 2, 2025 18:32
## Summary
- Implement structured logging with multiple log types and levels
- Add VERBOSE log level for detailed API call tracking
- Replace --verbose-logging flag with cleaner log level system
- Create comprehensive logging documentation

## Major Features
- **Centralized logging module** (`logging_config.py`) with JSON formatting
- **Five log levels**: ERROR, WARNING, INFO, VERBOSE, DEBUG
- **Multiple log types**: main, API, analysis, debug with automatic rotation
- **CLI integration**: `--log-level VERBOSE/DEBUG` and log viewer commands
- **Real-time monitoring**: Built-in log viewer with follow mode

## API & Token Tracking
- Detailed API call timing and success/failure logging
- Rate limiting event tracking with backoff strategies
- Token usage monitoring with cost calculations per phase
- Fallback estimation logging when collector unavailable

## Enhanced CLI
- Add `rulectl config logs` command with multiple viewing options
- Support for custom log directories via `--log-dir`
- Real-time log following with `--follow` option
- Multiple log type filtering (main, api, analysis, debug)

## Documentation
- Complete logging guide in LOGGING.md
- Updated README with all new logging features and examples
- Comprehensive usage examples and troubleshooting guides

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…ehensive tests

## CLI Architecture Improvements
- **BREAKING**: Move from `rulectl config logs` to direct `rulectl logs` command
- Much more intuitive and follows industry standards (docker logs, kubectl logs)
- Clean command separation: config=settings, logs=output, start=execution

## New Command Structure
```bash
# New direct command (cleaner)
rulectl logs --type api --follow     # Instead of config logs --log-type

# All logging options
rulectl logs                         # Show recent main logs
rulectl logs --type api             # Show API logs
rulectl logs --type analysis        # Show analysis summaries
rulectl logs --type debug           # Show debug info
rulectl logs --follow               # Real-time following
rulectl logs --lines 100            # More lines
```

## Comprehensive Test Suite
- **58 test cases** covering all logging functionality
- Core logging tests (log levels, JSON formatting, structured logging)
- CLI integration tests (options, commands, error handling)
- API monitoring tests (rate limiter, token tracker, performance)
- Test runner and documentation for easy maintenance

## Updated Documentation
- All examples updated to use new `rulectl logs` command
- Removed deprecated `--verbose-logging` and `config logs` references
- Complete test documentation with usage examples
- Architecture explanations for the CLI improvements

## Breaking Changes
- `rulectl config logs` → `rulectl logs` (clean migration path)
- `--log-type` → `--type` (shorter, cleaner option name)
- Clear error messages guide users to new commands

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@poiley
poiley force-pushed the feat/comprehensive-logging branch from f76bb41 to 2d134e9 Compare September 3, 2025 01:32
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.

1 participant