5.1 KiB
Log-Free Codebase Policy
Overview
The Project Mycelium maintains a log-free codebase in main and development branches as a core architectural design decision. This policy ensures clean, production-ready code and simplifies maintenance, debugging, and AI-assisted development.
Policy Statement
All log::
statements must be removed from the codebase before merging to main or development branches.
Rationale
1. Code Cleanliness
- Removes visual clutter and noise from the codebase
- Improves code readability and maintainability
- Reduces file size and complexity
2. Production Readiness
- Eliminates potential performance overhead from logging statements
- Prevents accidental logging of sensitive information
- Ensures consistent behavior across environments
3. AI-Assisted Development
- Simplifies code analysis and pattern recognition for AI tools
- Reduces token count and complexity for AI code generation
- Enables more accurate code migrations and refactoring
4. Maintenance Benefits
- Reduces merge conflicts from logging changes
- Eliminates outdated or inconsistent log messages
- Simplifies code review process
Implementation Guidelines
✅ Allowed Usage
- Feature Branches: Developers may use
log::
statements for troubleshooting and debugging in feature branches - Local Development: Temporary logging for development and testing purposes
- Debugging Sessions: Short-term logging to diagnose specific issues
❌ Prohibited Usage
- Main Branch: No
log::
statements allowed in main branch - Development Branch: No
log::
statements allowed in development branch - Production Code: No logging statements in production-ready code
- Permanent Logging: No long-term or permanent logging infrastructure
Enforcement
1. Pre-Merge Cleanup
All feature branches must have log::
statements removed before creating pull requests:
# Check for log statements before merging
find src -name "*.rs" -exec grep -l "log::" {} \;
# Remove all log statements (if any found)
find src -name "*.rs" -exec perl -i -pe 'BEGIN{undef $/;} s/\s*log::[^;]*;//g' {} \;
# Verify removal
cargo check --lib
2. Automated Checks
- CI/CD pipeline should include log statement detection
- Pre-commit hooks can prevent accidental commits with logging
- Code review checklist includes log statement verification
3. Migration History
- 2025-01-06: Removed 881+ log statements from entire codebase
- Dashboard Controller: 443 log statements removed
- Other Controllers: 438 log statements removed across 24 files
Alternative Approaches
For Debugging
Instead of permanent logging, use:
-
Conditional Compilation:
#[cfg(debug_assertions)] eprintln!("Debug: {}", value);
-
Feature Flags:
#[cfg(feature = "debug-logging")] log::debug!("Debug information");
-
Test-Only Logging:
#[cfg(test)] println!("Test debug: {}", value);
For Production Monitoring
- Use external monitoring tools (Prometheus, Grafana)
- Implement structured error handling with Result types
- Use application metrics instead of log statements
- Implement health check endpoints
Benefits Realized
1. Codebase Statistics
- Before: 881+ log statements across 24 files
- After: 0 log statements (100% reduction)
- Compilation: Clean builds with only minor unused variable warnings
2. Development Improvements
- Simplified ResponseBuilder migration process
- Reduced code complexity for AI-assisted refactoring
- Cleaner code reviews and merge processes
- Improved code readability and maintainability
3. Performance Benefits
- Reduced binary size
- Eliminated runtime logging overhead
- Faster compilation times
- Cleaner production deployments
Compliance
Developer Responsibilities
- Remove all
log::
statements before creating pull requests - Verify clean builds after log removal
- Use alternative debugging approaches for troubleshooting
- Follow the log-free policy consistently across all contributions
Code Review Requirements
- Check for log statements in all code reviews
- Verify compilation after any log-related changes
- Ensure policy compliance before approving merges
- Document any exceptions (if absolutely necessary)
Exceptions
No exceptions are currently allowed. The log-free policy is absolute for main and development branches.
If logging becomes absolutely necessary for specific use cases, it must be:
- Approved by the architecture team
- Implemented with feature flags
- Documented as an architectural decision
- Reviewed regularly for removal
Related Documentation
- Builder Pattern Architecture
- ResponseBuilder Migration Guide
- Code Quality Standards
- AI-Assisted Development Guidelines
Last Updated: 2025-01-06
Policy Version: 1.0
Status: Active and Enforced