Thank you for your interest in contributing to LogStructor! We welcome contributions from the community and are excited to see what you'll bring to the project.
- Python 3.11 or higher
- uv for dependency management (recommended)
- Git
-
Fork and clone the repository:
git clone https://github.com/your-username/logstructor.git cd logstructor -
Install dependencies using uv:
uv sync --all-groups
Or if you prefer pip:
pip install -e ".[test,linting,docs]" -
Verify your setup:
uv run pytest uv run ruff check uv run mypy logstructor
We maintain high code quality standards using automated tools:
- Ruff for linting and formatting
- MyPy for type checking
- Pytest for testing
Before submitting any changes, ensure your code passes all checks:
# Format code
uv run ruff format
# Check linting
uv run ruff check
# Type checking
uv run mypy logstructor
# Run tests
uv run pytest
# Run tests with coverage
uv run pytest --cov=logstructor --cov-report=htmlWe have comprehensive test coverage. Run the full test suite:
# All tests
uv run pytest
# Specific test file
uv run pytest tests/test_logger.py
# With coverage report
uv run pytest --cov=logstructor --cov-report=term-missing
# Async tests only
uv run pytest -k "async"Documentation is built with Sphinx and hosted as part of the project:
# Build documentation
cd docs
uv run sphinx-build -b html source build
# Serve locally (if you have a simple HTTP server)
cd build && python -m http.server 8000We welcome several types of contributions:
- Bug fixes - Fix issues in existing functionality
- Feature enhancements - Improve existing features
- New features - Add new functionality (please discuss first)
- Documentation - Improve docs, examples, or tutorials
- Tests - Add or improve test coverage
- Performance - Optimize existing code
For significant changes, please:
- Open an issue to discuss your proposed changes
- Check existing issues to avoid duplicate work
- Review the roadmap to align with project direction
-
Create a feature branch:
git checkout -b feature/your-feature-name
-
Make your changes following our coding standards
-
Add tests for any new functionality
-
Update documentation if needed
-
Ensure all checks pass:
uv run ruff check uv run mypy logstructor uv run pytest
We use conventional commits for automated changelog generation:
feat: add support for custom timestamp formats
fix: resolve context isolation issue in async functions
docs: improve context management examples
test: add tests for thread safety
refactor: simplify formatter initialization
Types: feat, fix, docs, test, refactor, perf, ci, chore
-
Ensure your branch is up to date:
git checkout main git pull upstream main git checkout your-branch git rebase main
-
Create a pull request with:
- Clear title and description
- Reference to related issues
- Summary of changes made
- Any breaking changes noted
-
Respond to feedback promptly and make requested changes
-
Ensure CI passes - all automated checks must pass
- Follow PEP 8 (enforced by Ruff)
- Use type hints for all public APIs
- Write comprehensive docstrings with examples
- Keep functions focused and testable
- Prefer composition over inheritance
def bind_context(**kwargs: Any) -> None:
"""
Bind key-value pairs to the current context's logging context.
These fields will be automatically included in all subsequent log entries
within the current context until cleared or overwritten.
Args:
**kwargs: Key-value pairs to bind to the context
Examples:
Basic usage:
>>> bind_context(request_id="req-123", user_id=456)
>>> logger.info("Processing request") # Will include request_id and user_id
Web application example:
>>> bind_context(request_id=request.id, user_id=request.user.id)
>>> logger.info("User login attempt") # Automatically includes context
"""
current_context = _context_data.get().copy()
current_context.update(kwargs)
_context_data.set(current_context)- Write tests for all new functionality
- Aim for high test coverage (>90%)
- Include both positive and negative test cases
- Test async functionality where applicable
- Use descriptive test names
def test_bind_context_overwrites_existing():
"""Test that bind_context overwrites existing keys."""
bind_context(user_id=123)
bind_context(user_id=456) # Should overwrite
context = get_context()
assert context["user_id"] == 456logstructor/
├── logstructor/ # Main package
│ ├── __init__.py # Public API
│ ├── logger.py # StructLogger implementation
│ ├── formatter.py # JSON formatter
│ ├── context.py # Context management
│ ├── config.py # Configuration utilities
│ └── exceptions.py # Custom exceptions
├── tests/ # Test suite
├── docs/ # Sphinx documentation
├── examples/ # Usage examples
└── pyproject.toml # Project configuration
- Backward Compatibility - Never break existing logging code
- Zero Dependencies - Keep the core lightweight
- Thread Safety - Support multi-threaded applications
- Async Support - First-class async/await support
- Performance - Minimal overhead over standard logging
- Simplicity - Easy to use, hard to misuse
Releases are automated using semantic-release:
- Merge changes to
mainbranch - Semantic-release analyzes commit messages
- Version is bumped automatically
- Changelog is generated
- Package is published to PyPI
- Issues: Open a GitHub issue for bugs or feature requests
- Discussions: Use GitHub Discussions for questions
- Documentation: Check the docs at
docs/
Contributors are recognized in:
- GitHub contributors list
- Release notes for significant contributions
- Documentation acknowledgments
Thank you for contributing to LogStructor! 🚀