Phase 2.5: Fix Foundation (CRITICAL) - Fixed 4 failing tests by adding cache attribute to mock_client fixture - Created comprehensive cache tests for Pages endpoint (test_pages_cache.py) - Added missing dependencies: pydantic[email] and aiohttp to core requirements - Updated requirements.txt with proper dependency versions - Achieved 82.67% test coverage with 454 passing tests Phase 2.6: Production Essentials - Implemented structured logging (wikijs/logging.py) * JSON and text log formatters * Configurable log levels and output destinations * Integration with client operations - Implemented metrics and telemetry (wikijs/metrics.py) * Request tracking with duration, status codes, errors * Latency percentiles (min, max, avg, p50, p95, p99) * Error rate calculation * Thread-safe metrics collection - Implemented rate limiting (wikijs/ratelimit.py) * Token bucket algorithm for request throttling * Per-endpoint rate limiting support * Configurable timeout handling * Burst capacity management - Created SECURITY.md policy * Vulnerability reporting procedures * Security best practices * Response timelines * Supported versions Documentation - Added comprehensive logging guide (docs/logging.md) - Added metrics and telemetry guide (docs/metrics.md) - Added rate limiting guide (docs/rate_limiting.md) - Updated README.md with production features section - Updated IMPROVEMENT_PLAN_2.md with completed checkboxes Testing - Created test suite for logging (tests/test_logging.py) - Created test suite for metrics (tests/test_metrics.py) - Created test suite for rate limiting (tests/test_ratelimit.py) - All 454 tests passing - Test coverage: 82.67% Breaking Changes: None Dependencies Added: pydantic[email], email-validator, dnspython 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
90 lines
1.6 KiB
Markdown
90 lines
1.6 KiB
Markdown
# Logging Guide
|
|
|
|
## Overview
|
|
|
|
The wikijs-python-sdk includes structured logging capabilities for production monitoring and debugging.
|
|
|
|
## Configuration
|
|
|
|
### Basic Setup
|
|
|
|
```python
|
|
from wikijs import WikiJSClient
|
|
import logging
|
|
|
|
# Enable debug logging
|
|
client = WikiJSClient(
|
|
"https://wiki.example.com",
|
|
auth="your-api-key",
|
|
log_level=logging.DEBUG
|
|
)
|
|
```
|
|
|
|
### JSON Logging
|
|
|
|
```python
|
|
from wikijs.logging import setup_logging
|
|
|
|
# Setup JSON logging to file
|
|
logger = setup_logging(
|
|
level=logging.INFO,
|
|
format_type="json",
|
|
output_file="wikijs.log"
|
|
)
|
|
```
|
|
|
|
### Text Logging
|
|
|
|
```python
|
|
from wikijs.logging import setup_logging
|
|
|
|
# Setup text logging to console
|
|
logger = setup_logging(
|
|
level=logging.INFO,
|
|
format_type="text"
|
|
)
|
|
```
|
|
|
|
## Log Levels
|
|
|
|
- `DEBUG`: Detailed information for debugging
|
|
- `INFO`: General informational messages
|
|
- `WARNING`: Warning messages
|
|
- `ERROR`: Error messages
|
|
- `CRITICAL`: Critical failures
|
|
|
|
## Log Fields
|
|
|
|
JSON logs include:
|
|
- `timestamp`: ISO 8601 timestamp
|
|
- `level`: Log level
|
|
- `message`: Log message
|
|
- `module`: Python module
|
|
- `function`: Function name
|
|
- `line`: Line number
|
|
- `extra`: Additional context
|
|
|
|
## Example Output
|
|
|
|
```json
|
|
{
|
|
"timestamp": "2025-10-23T10:15:30.123456",
|
|
"level": "INFO",
|
|
"logger": "wikijs",
|
|
"message": "Initializing WikiJSClient",
|
|
"module": "client",
|
|
"function": "__init__",
|
|
"line": 45,
|
|
"base_url": "https://wiki.example.com",
|
|
"timeout": 30
|
|
}
|
|
```
|
|
|
|
## Best Practices
|
|
|
|
1. Use appropriate log levels
|
|
2. Enable DEBUG only for development
|
|
3. Rotate log files in production
|
|
4. Monitor error rates
|
|
5. Include contextual information
|