Development Guide¶
This guide covers development setup, testing, code quality, and contribution guidelines for Logly.
Development Environment Setup¶
Prerequisites¶
- Python 3.10+
- Rust toolchain (for building the Rust backend)
- uv package manager
Installation¶
-
Clone the repository:
-
Install dependencies:
-
Verify installation:
Testing¶
Logly maintains comprehensive test coverage with 96%+ code coverage across all functionality.
Running Tests¶
# Run all tests
uv run pytest
# Run tests with coverage report
uv run pytest --cov=logly --cov-report=term-missing
# Run specific test file
uv run pytest tests/test_logger_features.py
# Run specific test
uv run pytest tests/test_logger_features.py::test_all_log_levels -v
Test Structure¶
Tests are organized in the tests/
directory:
test_logly.py
- Basic functionality teststest_logger_features.py
- Core logging featurestest_performance_features.py
- Performance and edge cases
Rust Tests¶
Logly includes comprehensive Rust unit tests for the backend:
# Run all Rust tests
cargo test --lib
# Run Rust tests with output
cargo test --lib -- --nocapture
# Run specific Rust test module
cargo test --lib backend::logging::tests
Writing Tests¶
When adding new features, ensure comprehensive test coverage:
def test_new_feature(tmp_path):
"""Test description for new feature."""
# Setup
logger.add(str(tmp_path / "test.log"))
logger.configure(level="INFO")
# Test the feature
# ... test code ...
# Assertions
# ... verify behavior ...
logger.complete()
Code Quality¶
Logly maintains a 10.00/10 pylint score and follows strict code quality standards.
Code Analysis¶
# Run pylint on source code
uv run pylint logly/
# Run pylint on tests
uv run pylint tests/
# Run on entire codebase
uv run pylint logly/ tests/
Code Style¶
- Follow PEP 8 style guidelines
- Use type hints for all function parameters and return values
- Add comprehensive docstrings for all public functions
- Keep line length under 100 characters (with justified exceptions)
- Use descriptive variable names
Pre-commit Hooks¶
Install pre-commit hooks to automatically check code quality:
Building and Packaging¶
Building the Rust Extension¶
# Debug build (fast compilation, unoptimized)
cargo build
# Release build (optimized for performance)
cargo build --release
# Build Python wheel (debug mode)
uv run maturin develop
# Build Python wheel (release mode with optimizations)
uv run maturin develop --release
Rust Performance Optimizations¶
Logly uses aggressive Rust compiler optimizations for maximum performance:
Release Profile Configuration (Cargo.toml
):
[profile.release]
opt-level = 3 # Maximum optimization
lto = "fat" # Link-time optimization (smaller, faster)
codegen-units = 1 # Single codegen unit (better optimization)
strip = true # Strip symbols (smaller binary)
panic = "abort" # Smaller binary, faster panic handling
Performance Impact: - Binary Size: ~40% smaller with LTO and stripping - Execution Speed: ~15-20% faster with LTO - Compile Time: Slower (expected for release builds)
Development vs Release:
Profile | Optimization | Binary Size | Compile Time | Use Case |
---|---|---|---|---|
Debug | None (opt-level=0) | Large | Fast | Development, testing |
Release | Maximum (opt-level=3) | Small | Slow | Production, benchmarks |
Building for Production:
# Build optimized wheel for production
uv run maturin build --release
# Install optimized wheel
pip install target/wheels/*.whl
Profiling Performance:
# Profile Rust code with flamegraph
cargo install flamegraph
cargo flamegraph --bench your_benchmark
# Profile Python code with cProfile
python -m cProfile -o profile.stats your_script.py
Building Documentation¶
# Build docs locally
uv run mkdocs build
# Serve docs locally for development
uv run mkdocs serve
# Deploy docs (requires proper permissions)
uv run mkdocs gh-deploy
Performance Testing¶
Logly includes comprehensive benchmarks to ensure performance standards.
Running Benchmarks¶
# File logging benchmark
uv run python bench/benchmark_logging.py
# Concurrency benchmark
uv run python bench/benchmark_concurrency.py
# Latency microbenchmark
uv run python bench/benchmark_latency.py
# Matrix benchmark (comprehensive)
uv run python bench/benchmark_matrix.py
Benchmark Results¶
Current performance metrics (as of October 2025):
- File Logging: ~150,000 messages/second
- Concurrent Logging: ~400,000 messages/second (4 threads)
- Latency: p50 < 10μs, p95 < 50μs, p99 < 100μs
Contributing¶
Development Workflow¶
- Fork and clone the repository
- Create a feature branch from
main
- Make changes following the code quality guidelines
- Add tests for new functionality
- Run the full test suite and ensure all checks pass
- Update documentation if needed
- Submit a pull request
Pull Request Checklist¶
- Tests pass (
uv run pytest
) - Code quality checks pass (
uv run pylint logly/ tests/
) - Coverage remains at 96%+ (
uv run pytest --cov=logly
) - Documentation updated if needed
- Changelog updated for user-facing changes
- Commit messages follow conventional format
Commit Message Format¶
Types: feat
, fix
, docs
, style
, refactor
, test
, chore
Architecture Overview¶
Core Components¶
- Python API (
logly/__init__.py
): User-facing logging interface - Rust Backend (
src/
): High-performance logging implementation - PyO3 Bindings (
src/lib.rs
): Python-Rust interop layer
Key Design Decisions¶
- Rust Backend: Provides memory safety and performance
- Async by Default: Non-blocking logging operations
- Callback System: Extensible logging pipeline
- Context Binding: Structured logging support
Troubleshooting¶
Common Issues¶
Import Error: Ensure the Rust extension is built
Test Failures: Check Python and Rust versions
Performance Issues: Run benchmarks to identify bottlenecks
Getting Help¶
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Logly Docs
Release Process¶
For maintainers:
- Update version in
Cargo.toml
andpyproject.toml
- Update
CHANGELOG.md
but I use the release draft feature of GitHub - Create git tag
- Build and publish to PyPI
- Deploy documentation