Skip to content

Commit c860b2c

Browse files
IntegerAlexgitbot
andcommitted
feat(async): add flush semantics and enhanced test utilities
Implement comprehensive shutdown patterns and flush semantics for the functional async logging backend. This update introduces the shutdown_async_backend utility to Co-authored-by: gitbot <gitbot@gossorg.in>
1 parent 794771f commit c860b2c

4 files changed

Lines changed: 84 additions & 3 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,5 @@ logs/
167167
# Documentation build
168168
documentation/build/
169169
documentation/.docusaurus/
170-
documentation/node_modules/
170+
documentation/node_modules/
171+
.gitbotrc.json

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
- Async logging flush semantics documentation and shutdown patterns guide.
12+
- New guides: `testing-patterns.md` (async logger testing), `common-pitfalls.md`.
13+
- `AsyncConfig` validation with helpful error messages.
14+
- Async logger test utilities: `wait_for_async_queue_drain`, `async_logger_with_teardown` fixture.
15+
- Export of `shutdown_async_backend` from main `kakashi` package.
16+
17+
### Changed
18+
- README license reference corrected to LGPL-2.1.
19+
- Expanded async-backends documentation with flush semantics and shutdown patterns.
20+
- Deprecated legacy `AsyncLogger` (removal planned for v0.4.0); use `kakashi.core.async_interface.get_async_logger`.
21+
- Type hints completed in `logger.py`, `async_interface.py`.
22+
- Deprecations doc now documents dual async systems and migration path.
23+
24+
### Fixed
25+
- Session test teardown now shuts down both legacy and functional async backends.
26+
1027
## [0.2.1] - 2026-02-05
1128

1229
### Changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ kakashi/
7272

7373
### Basic Usage
7474

75+
**Tip:** For production apps using async logging, register shutdown at startup to prevent message loss:
76+
77+
```python
78+
import atexit
79+
from kakashi import shutdown_async_logging, shutdown_async_backend
80+
atexit.register(shutdown_async_backend) # For functional async; use shutdown_async_logging for legacy
81+
```
82+
7583
```python
7684
from kakashi import get_logger, get_async_logger
7785

@@ -235,7 +243,7 @@ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) f
235243

236244
## 📄 License
237245

238-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
246+
This project is licensed under the LGPL-2.1 License - see the [LICENSE](LICENSE) file for details.
239247

240248
## ⚖️ Legal Disclaimers
241249

@@ -262,4 +270,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
262270

263271
---
264272

265-
**Kakashi v0.2.0** - Professional High-Performance Logging for Python
273+
**Kakashi v0.2.1** - Professional High-Performance Logging for Python

performance_tests/conftest.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ def cleanup_async_logging():
2222
yield
2323
from kakashi import shutdown_async_logging
2424
shutdown_async_logging()
25+
try:
26+
from kakashi.core.async_interface import shutdown_async_backend
27+
shutdown_async_backend(timeout=2.0)
28+
except ImportError:
29+
pass
2530

2631
@pytest.fixture(scope="session")
2732
def temp_test_dir() -> Generator[Path, None, None]:
@@ -137,3 +142,53 @@ def kakashi_structured_logger():
137142
"""Create a fresh Kakashi structured logger for each test."""
138143
from kakashi.core import create_structured_logger
139144
return create_structured_logger("test_structured_logger")
145+
146+
147+
# =============================================================================
148+
# Async logger test utilities
149+
# =============================================================================
150+
151+
def wait_for_async_queue_drain(
152+
timeout: float = 5.0,
153+
poll_interval: float = 0.05,
154+
) -> bool:
155+
"""
156+
Wait until the functional async backend queue is empty or timeout.
157+
158+
Use before asserting on log output when using async loggers.
159+
160+
Returns:
161+
True if queue drained, False if timeout reached.
162+
"""
163+
import time
164+
try:
165+
from kakashi.core.async_interface import get_async_stats
166+
except ImportError:
167+
return False
168+
start = time.time()
169+
while time.time() - start < timeout:
170+
stats = get_async_stats()
171+
if stats.get("queue_size", 0) == 0:
172+
return True
173+
time.sleep(poll_interval)
174+
return False
175+
176+
177+
@pytest.fixture
178+
def async_logger_with_teardown():
179+
"""
180+
Functional async logger that shuts down cleanly after each test.
181+
182+
Use for tests that need async logging and must drain the queue
183+
before asserting on output.
184+
"""
185+
try:
186+
from kakashi.core.async_interface import (
187+
get_async_logger,
188+
shutdown_async_backend,
189+
)
190+
except ImportError:
191+
pytest.skip("kakashi.core.async_interface not available")
192+
logger = get_async_logger("test.async_teardown")
193+
yield logger
194+
shutdown_async_backend(timeout=2.0)

0 commit comments

Comments
 (0)