debug-log-server 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- debug_log_server-0.1.0/MANIFEST.in +6 -0
- debug_log_server-0.1.0/PKG-INFO +402 -0
- debug_log_server-0.1.0/README.md +370 -0
- debug_log_server-0.1.0/debug_log_server.egg-info/PKG-INFO +402 -0
- debug_log_server-0.1.0/debug_log_server.egg-info/SOURCES.txt +11 -0
- debug_log_server-0.1.0/debug_log_server.egg-info/dependency_links.txt +1 -0
- debug_log_server-0.1.0/debug_log_server.egg-info/entry_points.txt +2 -0
- debug_log_server-0.1.0/debug_log_server.egg-info/requires.txt +10 -0
- debug_log_server-0.1.0/debug_log_server.egg-info/top_level.txt +2 -0
- debug_log_server-0.1.0/pyproject.toml +55 -0
- debug_log_server-0.1.0/requirements.txt +4 -0
- debug_log_server-0.1.0/setup.cfg +4 -0
- debug_log_server-0.1.0/static/index.html +371 -0
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: debug-log-server
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Debug log collection and query service based on FastAPI
|
|
5
|
+
Author-email: dengshi <dengshi@mercator.cn>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/dengshihub/debuglogger
|
|
8
|
+
Project-URL: Documentation, https://github.com/dengshihub/debuglogger#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/dengshihub/debuglogger.git
|
|
10
|
+
Project-URL: Issues, https://github.com/dengshihub/debuglogger/issues
|
|
11
|
+
Keywords: debug,log,logging,fastapi,monitoring,error-tracking
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Requires-Python: >=3.8
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
Requires-Dist: fastapi>=0.104.0
|
|
24
|
+
Requires-Dist: uvicorn[standard]>=0.24.0
|
|
25
|
+
Requires-Dist: pydantic>=2.0.0
|
|
26
|
+
Requires-Dist: python-jose[cryptography]>=3.3.0
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
29
|
+
Requires-Dist: httpx>=0.24.0; extra == "dev"
|
|
30
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
31
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
|
32
|
+
|
|
33
|
+
# Debug Log Server
|
|
34
|
+
|
|
35
|
+
Debug log collection and query service based on FastAPI.
|
|
36
|
+
|
|
37
|
+
## ๐ฆ Installation
|
|
38
|
+
|
|
39
|
+
### From PyPI
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install debug-log-server
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### From Source
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
git clone https://github.com/dengshihub/debuglogger.git
|
|
49
|
+
cd debuglogger/backend
|
|
50
|
+
pip install -e .
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## ๐ Quick Start
|
|
54
|
+
|
|
55
|
+
### Start Server
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Basic usage
|
|
59
|
+
debug-log-server
|
|
60
|
+
|
|
61
|
+
# With custom log directory
|
|
62
|
+
DEBUG_LOG_DIR=/var/log/debug-logs debug-log-server
|
|
63
|
+
|
|
64
|
+
# With custom port
|
|
65
|
+
debug-log-server --port 9000
|
|
66
|
+
|
|
67
|
+
# With custom host and port
|
|
68
|
+
debug-log-server --host 0.0.0.0 --port 8000
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Environment Variables
|
|
72
|
+
|
|
73
|
+
- `DEBUG_LOG_DIR`: Log storage directory (default: `./debug-logs`)
|
|
74
|
+
- `DEBUG_AUTH`: Enable authentication debug mode (default: `false`)
|
|
75
|
+
|
|
76
|
+
## ๐ API Documentation
|
|
77
|
+
|
|
78
|
+
### POST /api/debug-log
|
|
79
|
+
|
|
80
|
+
Receive debug logs from frontend.
|
|
81
|
+
|
|
82
|
+
**Request Body:**
|
|
83
|
+
```json
|
|
84
|
+
{
|
|
85
|
+
"logs": [
|
|
86
|
+
{
|
|
87
|
+
"sessionId": "session-123",
|
|
88
|
+
"timestamp": 1717564800000,
|
|
89
|
+
"type": "console",
|
|
90
|
+
"level": "log",
|
|
91
|
+
"message": "Hello World",
|
|
92
|
+
"url": "https://example.com"
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
"source": "frontend"
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Response:**
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"status": "ok",
|
|
103
|
+
"received": 1
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### GET /api/debug-log/list
|
|
108
|
+
|
|
109
|
+
List all log files.
|
|
110
|
+
|
|
111
|
+
**Query Parameters:**
|
|
112
|
+
- `source`: Filter by source (optional)
|
|
113
|
+
|
|
114
|
+
**Response:**
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"logs": [
|
|
118
|
+
{
|
|
119
|
+
"name": "frontend.log",
|
|
120
|
+
"path": "/var/log/debug-logs/frontend/frontend.log",
|
|
121
|
+
"size": 1024,
|
|
122
|
+
"modified": "2024-06-05T10:30:00"
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### GET /api/debug-log/{source}
|
|
129
|
+
|
|
130
|
+
Get logs from a specific source.
|
|
131
|
+
|
|
132
|
+
**Query Parameters:**
|
|
133
|
+
- `limit`: Maximum number of entries to return (default: 100)
|
|
134
|
+
|
|
135
|
+
**Response:**
|
|
136
|
+
```json
|
|
137
|
+
{
|
|
138
|
+
"source": "frontend",
|
|
139
|
+
"entries": [
|
|
140
|
+
{
|
|
141
|
+
"sessionId": "session-123",
|
|
142
|
+
"timestamp": 1717564800000,
|
|
143
|
+
"type": "console",
|
|
144
|
+
"level": "log",
|
|
145
|
+
"message": "Hello World"
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## ๐ณ Docker
|
|
152
|
+
|
|
153
|
+
### Build Image
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
docker build -t debug-log-server .
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Run Container
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
docker run -d \
|
|
163
|
+
-p 8000:8000 \
|
|
164
|
+
-v /var/log/debug-logs:/app/debug-logs \
|
|
165
|
+
--name debug-log-server \
|
|
166
|
+
debug-log-server
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Docker Compose
|
|
170
|
+
|
|
171
|
+
```yaml
|
|
172
|
+
version: '3.8'
|
|
173
|
+
|
|
174
|
+
services:
|
|
175
|
+
debug-log-server:
|
|
176
|
+
image: debug-log-server:latest
|
|
177
|
+
ports:
|
|
178
|
+
- "8000:8000"
|
|
179
|
+
volumes:
|
|
180
|
+
- ./debug-logs:/app/debug-logs
|
|
181
|
+
environment:
|
|
182
|
+
- DEBUG_LOG_DIR=/app/debug-logs
|
|
183
|
+
restart: unless-stopped
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## ๐ง Configuration
|
|
187
|
+
|
|
188
|
+
### Basic Configuration
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
# config.py
|
|
192
|
+
import os
|
|
193
|
+
|
|
194
|
+
LOG_DIR = os.getenv("DEBUG_LOG_DIR", "./debug-logs")
|
|
195
|
+
HOST = os.getenv("HOST", "0.0.0.0")
|
|
196
|
+
PORT = int(os.getenv("PORT", "8000"))
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Advanced Configuration
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
# config.py
|
|
203
|
+
from pydantic import BaseSettings
|
|
204
|
+
|
|
205
|
+
class Settings(BaseSettings):
|
|
206
|
+
log_dir: str = "./debug-logs"
|
|
207
|
+
host: str = "0.0.0.0"
|
|
208
|
+
port: int = 8000
|
|
209
|
+
debug_auth: bool = False
|
|
210
|
+
|
|
211
|
+
class Config:
|
|
212
|
+
env_prefix = "DEBUG_"
|
|
213
|
+
|
|
214
|
+
settings = Settings()
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## ๐ Security
|
|
218
|
+
|
|
219
|
+
### Authentication
|
|
220
|
+
|
|
221
|
+
The server supports JWT authentication for protected routes:
|
|
222
|
+
|
|
223
|
+
```python
|
|
224
|
+
from fastapi import Depends
|
|
225
|
+
from debug_log_server import debug_auth
|
|
226
|
+
|
|
227
|
+
@app.get("/api/protected")
|
|
228
|
+
async def protected_route(token: str = Depends(debug_auth)):
|
|
229
|
+
return {"message": "This is a protected route"}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### CORS
|
|
233
|
+
|
|
234
|
+
CORS is enabled by default for all origins. For production, configure it properly:
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
from fastapi.middleware.cors import CORSMiddleware
|
|
238
|
+
|
|
239
|
+
app.add_middleware(
|
|
240
|
+
CORSMiddleware,
|
|
241
|
+
allow_origins=["https://your-domain.com"], # Specify allowed origins
|
|
242
|
+
allow_credentials=True,
|
|
243
|
+
allow_methods=["GET", "POST"],
|
|
244
|
+
allow_headers=["*"],
|
|
245
|
+
)
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## ๐ Monitoring
|
|
249
|
+
|
|
250
|
+
### Health Check
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
curl http://localhost:8000/
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Log Statistics
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
curl http://localhost:8000/api/debug-log/list
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## ๐งช Testing
|
|
263
|
+
|
|
264
|
+
### Install Test Dependencies
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
pip install debug-log-server[dev]
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Run Tests
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
pytest tests/
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Test with httpx
|
|
277
|
+
|
|
278
|
+
```python
|
|
279
|
+
from fastapi.testclient import TestClient
|
|
280
|
+
from main import app
|
|
281
|
+
|
|
282
|
+
client = TestClient(app)
|
|
283
|
+
|
|
284
|
+
def test_receive_log():
|
|
285
|
+
response = client.post("/api/debug-log", json={
|
|
286
|
+
"logs": [{
|
|
287
|
+
"sessionId": "test",
|
|
288
|
+
"timestamp": 1717564800000,
|
|
289
|
+
"type": "console",
|
|
290
|
+
"message": "test"
|
|
291
|
+
}],
|
|
292
|
+
"source": "test"
|
|
293
|
+
})
|
|
294
|
+
assert response.status_code == 200
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## ๐ Examples
|
|
298
|
+
|
|
299
|
+
### Python Client
|
|
300
|
+
|
|
301
|
+
```python
|
|
302
|
+
import requests
|
|
303
|
+
|
|
304
|
+
# Send logs
|
|
305
|
+
response = requests.post('http://localhost:8000/api/debug-log', json={
|
|
306
|
+
"logs": [{
|
|
307
|
+
"sessionId": "session-123",
|
|
308
|
+
"timestamp": 1717564800000,
|
|
309
|
+
"type": "console",
|
|
310
|
+
"level": "log",
|
|
311
|
+
"message": "Hello from Python"
|
|
312
|
+
}],
|
|
313
|
+
"source": "python-client"
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
print(response.json())
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### JavaScript Client
|
|
320
|
+
|
|
321
|
+
```javascript
|
|
322
|
+
// Using fetch
|
|
323
|
+
fetch('http://localhost:8000/api/debug-log', {
|
|
324
|
+
method: 'POST',
|
|
325
|
+
headers: { 'Content-Type': 'application/json' },
|
|
326
|
+
body: JSON.stringify({
|
|
327
|
+
logs: [{
|
|
328
|
+
sessionId: 'session-123',
|
|
329
|
+
timestamp: Date.now(),
|
|
330
|
+
type: 'console',
|
|
331
|
+
level: 'log',
|
|
332
|
+
message: 'Hello from JavaScript'
|
|
333
|
+
}],
|
|
334
|
+
source: 'javascript-client'
|
|
335
|
+
})
|
|
336
|
+
})
|
|
337
|
+
.then(response => response.json())
|
|
338
|
+
.then(data => console.log(data));
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
## ๐ Deployment
|
|
342
|
+
|
|
343
|
+
### Systemd Service
|
|
344
|
+
|
|
345
|
+
```ini
|
|
346
|
+
# /etc/systemd/system/debug-log-server.service
|
|
347
|
+
[Unit]
|
|
348
|
+
Description=Debug Log Server
|
|
349
|
+
After=network.target
|
|
350
|
+
|
|
351
|
+
[Service]
|
|
352
|
+
Type=simple
|
|
353
|
+
User=www-data
|
|
354
|
+
WorkingDirectory=/opt/debug-log-server
|
|
355
|
+
Environment="DEBUG_LOG_DIR=/var/log/debug-logs"
|
|
356
|
+
ExecStart=/usr/local/bin/debug-log-server
|
|
357
|
+
Restart=always
|
|
358
|
+
|
|
359
|
+
[Install]
|
|
360
|
+
WantedBy=multi-user.target
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
```bash
|
|
364
|
+
sudo systemctl enable debug-log-server
|
|
365
|
+
sudo systemctl start debug-log-server
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### Nginx Reverse Proxy
|
|
369
|
+
|
|
370
|
+
```nginx
|
|
371
|
+
server {
|
|
372
|
+
listen 80;
|
|
373
|
+
server_name logs.your-domain.com;
|
|
374
|
+
|
|
375
|
+
location / {
|
|
376
|
+
proxy_pass http://127.0.0.1:8000;
|
|
377
|
+
proxy_set_header Host $host;
|
|
378
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
379
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
380
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
## ๐ Related Projects
|
|
386
|
+
|
|
387
|
+
- **@dengshi/debug-logger**: Frontend log collection library (npm)
|
|
388
|
+
- **playwright-collector**: Playwright-based log collector
|
|
389
|
+
|
|
390
|
+
## ๐ License
|
|
391
|
+
|
|
392
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
393
|
+
|
|
394
|
+
## ๐ค Contributing
|
|
395
|
+
|
|
396
|
+
Contributions are welcome! Please read our [Contributing Guide](../CONTRIBUTING.md) for details.
|
|
397
|
+
|
|
398
|
+
## ๐ Support
|
|
399
|
+
|
|
400
|
+
- ๐ [Documentation](https://github.com/dengshihub/debuglogger#readme)
|
|
401
|
+
- ๐ [Issue Tracker](https://github.com/dengshihub/debuglogger/issues)
|
|
402
|
+
- ๐ฌ [Discussions](https://github.com/dengshihub/debuglogger/discussions)
|