Skip to content

Commit 5d55333

Browse files
authored
feat: finalize first basis version (#1)
1 parent bd99f59 commit 5d55333

24 files changed

Lines changed: 3550 additions & 58 deletions

.github/dependabot.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "uv"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
allow:
8+
- dependency-type: "development"
9+
commit-message:
10+
prefix: "chore"
11+
include: "scope"
12+
labels:
13+
- "dependencies"
14+
open-pull-requests-limit: 5
15+
16+
- package-ecosystem: "github-actions"
17+
directory: "/"
18+
schedule:
19+
interval: "monthly"
20+
commit-message:
21+
prefix: "chore"
22+
include: "scope"
23+
labels:
24+
- "ci"

.github/workflows/ci.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@ jobs:
5757
run: uv sync --group test
5858

5959
- name: Run unit tests
60-
run: uv run pytest --cov --junitxml=junit.xml -o junit_family=legacy
60+
run: uv run pytest --cov -v --cov-report=term --cov-report=xml
6161

6262
- name: Upload test results to Codecov
63-
if: ${{ !cancelled() }}
64-
uses: codecov/test-results-action@v1
63+
uses: codecov/codecov-action@v5
6564
with:
6665
token: ${{ secrets.CODECOV_TOKEN }}
6766

@@ -106,3 +105,27 @@ jobs:
106105
export UV_PUBLISH_TOKEN=${{ secrets.UV_PUBLISH_TOKEN }}
107106
uv build
108107
uv publish
108+
109+
pages:
110+
name: "Publish Documentation to GitHub Pages"
111+
if: github.ref == 'refs/heads/main'
112+
needs: release
113+
114+
runs-on: ubuntu-latest
115+
container:
116+
image: ghcr.io/astral-sh/uv:0.6-python3.11-bookworm
117+
118+
steps:
119+
- uses: actions/checkout@v4
120+
121+
- name: Install docs dependencies
122+
run: uv sync --group docs
123+
124+
- name: Build documentation
125+
run: uv run sphinx-build -b html docs/source public
126+
127+
- name: Publish to GitHub Pages
128+
uses: peaceiris/actions-gh-pages@v4
129+
with:
130+
github_token: ${{ secrets.GITHUB_TOKEN }}
131+
publish_dir: public

CODE_OF_CONDUCT.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## ⭐ Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our project and community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8+
9+
---
10+
11+
## ⭐ Our Standards
12+
13+
Examples of behavior that contributes to a positive environment:
14+
- Using welcoming and inclusive language.
15+
- Being respectful of differing viewpoints and experiences.
16+
- Accepting constructive criticism gracefully.
17+
- Showing empathy toward other community members.
18+
19+
Examples of unacceptable behavior:
20+
- The use of sexualized language or imagery and unwelcome sexual attention.
21+
- Trolling, insulting or derogatory comments, and personal or political attacks.
22+
- Public or private harassment.
23+
- Publishing others' private information (e.g. physical or electronic address) without explicit permission.
24+
- Other conduct which could reasonably be considered inappropriate.
25+
26+
---
27+
28+
## ⭐ Enforcement Responsibilities
29+
30+
Project maintainers are responsible for clarifying and enforcing standards of acceptable behavior and will take appropriate corrective action in response to any instances of unacceptable behavior.
31+
32+
---
33+
34+
## ⭐ Scope
35+
36+
This Code of Conduct applies within all project spaces, including issues, pull requests, and all communication channels (e.g. discussions, Slack, etc.).
37+
38+
---
39+
40+
## ⭐ Attribution
41+
42+
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 2.1.

CONTRIBUTING.md

Lines changed: 277 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,277 @@
1+
# Contributing to LogStructor
2+
3+
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.
4+
5+
## Getting Started
6+
7+
### Prerequisites
8+
9+
- Python 3.11 or higher
10+
- [uv](https://docs.astral.sh/uv/) for dependency management (recommended)
11+
- Git
12+
13+
### Setting Up Your Development Environment
14+
15+
1. **Fork and clone the repository:**
16+
```bash
17+
git clone https://github.com/your-username/logstructor.git
18+
cd logstructor
19+
```
20+
21+
2. **Install dependencies using uv:**
22+
```bash
23+
uv sync --all-groups
24+
```
25+
26+
Or if you prefer pip:
27+
```bash
28+
pip install -e ".[test,linting,docs]"
29+
```
30+
31+
3. **Verify your setup:**
32+
```bash
33+
uv run pytest
34+
uv run ruff check
35+
uv run mypy logstructor
36+
```
37+
38+
## Development Workflow
39+
40+
### Code Style and Quality
41+
42+
We maintain high code quality standards using automated tools:
43+
44+
- **Ruff** for linting and formatting
45+
- **MyPy** for type checking
46+
- **Pytest** for testing
47+
48+
Before submitting any changes, ensure your code passes all checks:
49+
50+
```bash
51+
# Format code
52+
uv run ruff format
53+
54+
# Check linting
55+
uv run ruff check
56+
57+
# Type checking
58+
uv run mypy logstructor
59+
60+
# Run tests
61+
uv run pytest
62+
63+
# Run tests with coverage
64+
uv run pytest --cov=logstructor --cov-report=html
65+
```
66+
67+
### Running Tests
68+
69+
We have comprehensive test coverage. Run the full test suite:
70+
71+
```bash
72+
# All tests
73+
uv run pytest
74+
75+
# Specific test file
76+
uv run pytest tests/test_logger.py
77+
78+
# With coverage report
79+
uv run pytest --cov=logstructor --cov-report=term-missing
80+
81+
# Async tests only
82+
uv run pytest -k "async"
83+
```
84+
85+
### Documentation
86+
87+
Documentation is built with Sphinx and hosted as part of the project:
88+
89+
```bash
90+
# Build documentation
91+
cd docs
92+
uv run sphinx-build -b html source build
93+
94+
# Serve locally (if you have a simple HTTP server)
95+
cd build && python -m http.server 8000
96+
```
97+
98+
## Contributing Guidelines
99+
100+
### Types of Contributions
101+
102+
We welcome several types of contributions:
103+
104+
- **Bug fixes** - Fix issues in existing functionality
105+
- **Feature enhancements** - Improve existing features
106+
- **New features** - Add new functionality (please discuss first)
107+
- **Documentation** - Improve docs, examples, or tutorials
108+
- **Tests** - Add or improve test coverage
109+
- **Performance** - Optimize existing code
110+
111+
### Before You Start
112+
113+
For significant changes, please:
114+
115+
1. **Open an issue** to discuss your proposed changes
116+
2. **Check existing issues** to avoid duplicate work
117+
3. **Review the roadmap** to align with project direction
118+
119+
### Making Changes
120+
121+
1. **Create a feature branch:**
122+
```bash
123+
git checkout -b feature/your-feature-name
124+
```
125+
126+
2. **Make your changes** following our coding standards
127+
128+
3. **Add tests** for any new functionality
129+
130+
4. **Update documentation** if needed
131+
132+
5. **Ensure all checks pass:**
133+
```bash
134+
uv run ruff check
135+
uv run mypy logstructor
136+
uv run pytest
137+
```
138+
139+
### Commit Messages
140+
141+
We use conventional commits for automated changelog generation:
142+
143+
```
144+
feat: add support for custom timestamp formats
145+
fix: resolve context isolation issue in async functions
146+
docs: improve context management examples
147+
test: add tests for thread safety
148+
refactor: simplify formatter initialization
149+
```
150+
151+
Types: `feat`, `fix`, `docs`, `test`, `refactor`, `perf`, `ci`, `chore`
152+
153+
### Pull Request Process
154+
155+
1. **Ensure your branch is up to date:**
156+
```bash
157+
git checkout main
158+
git pull upstream main
159+
git checkout your-branch
160+
git rebase main
161+
```
162+
163+
2. **Create a pull request** with:
164+
- Clear title and description
165+
- Reference to related issues
166+
- Summary of changes made
167+
- Any breaking changes noted
168+
169+
3. **Respond to feedback** promptly and make requested changes
170+
171+
4. **Ensure CI passes** - all automated checks must pass
172+
173+
## Code Standards
174+
175+
### Python Code Style
176+
177+
- Follow PEP 8 (enforced by Ruff)
178+
- Use type hints for all public APIs
179+
- Write comprehensive docstrings with examples
180+
- Keep functions focused and testable
181+
- Prefer composition over inheritance
182+
183+
### Example of Good Code Style
184+
185+
```python
186+
def bind_context(**kwargs: Any) -> None:
187+
"""
188+
Bind key-value pairs to the current context's logging context.
189+
190+
These fields will be automatically included in all subsequent log entries
191+
within the current context until cleared or overwritten.
192+
193+
Args:
194+
**kwargs: Key-value pairs to bind to the context
195+
196+
Examples:
197+
Basic usage:
198+
>>> bind_context(request_id="req-123", user_id=456)
199+
>>> logger.info("Processing request") # Will include request_id and user_id
200+
201+
Web application example:
202+
>>> bind_context(request_id=request.id, user_id=request.user.id)
203+
>>> logger.info("User login attempt") # Automatically includes context
204+
"""
205+
current_context = _context_data.get().copy()
206+
current_context.update(kwargs)
207+
_context_data.set(current_context)
208+
```
209+
210+
### Testing Standards
211+
212+
- Write tests for all new functionality
213+
- Aim for high test coverage (>90%)
214+
- Include both positive and negative test cases
215+
- Test async functionality where applicable
216+
- Use descriptive test names
217+
218+
```python
219+
def test_bind_context_overwrites_existing():
220+
"""Test that bind_context overwrites existing keys."""
221+
bind_context(user_id=123)
222+
bind_context(user_id=456) # Should overwrite
223+
224+
context = get_context()
225+
assert context["user_id"] == 456
226+
```
227+
228+
## Project Structure
229+
230+
```
231+
logstructor/
232+
├── logstructor/ # Main package
233+
│ ├── __init__.py # Public API
234+
│ ├── logger.py # StructLogger implementation
235+
│ ├── formatter.py # JSON formatter
236+
│ ├── context.py # Context management
237+
│ ├── config.py # Configuration utilities
238+
│ └── exceptions.py # Custom exceptions
239+
├── tests/ # Test suite
240+
├── docs/ # Sphinx documentation
241+
├── examples/ # Usage examples
242+
└── pyproject.toml # Project configuration
243+
```
244+
245+
## Design Principles
246+
247+
1. **Backward Compatibility** - Never break existing logging code
248+
2. **Zero Dependencies** - Keep the core lightweight
249+
3. **Thread Safety** - Support multi-threaded applications
250+
4. **Async Support** - First-class async/await support
251+
5. **Performance** - Minimal overhead over standard logging
252+
6. **Simplicity** - Easy to use, hard to misuse
253+
254+
## Release Process
255+
256+
Releases are automated using semantic-release:
257+
258+
1. Merge changes to `main` branch
259+
2. Semantic-release analyzes commit messages
260+
3. Version is bumped automatically
261+
4. Changelog is generated
262+
5. Package is published to PyPI
263+
264+
## Getting Help
265+
266+
- **Issues**: Open a GitHub issue for bugs or feature requests
267+
- **Discussions**: Use GitHub Discussions for questions
268+
- **Documentation**: Check the docs at `docs/`
269+
270+
## Recognition
271+
272+
Contributors are recognized in:
273+
- GitHub contributors list
274+
- Release notes for significant contributions
275+
- Documentation acknowledgments
276+
277+
Thank you for contributing to LogStructor! 🚀

0 commit comments

Comments
 (0)