python-log-viewer 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.
- python_log_viewer-0.1.0/.gitignore +20 -0
- python_log_viewer-0.1.0/LICENSE +21 -0
- python_log_viewer-0.1.0/PKG-INFO +283 -0
- python_log_viewer-0.1.0/README.md +243 -0
- python_log_viewer-0.1.0/examples/README.md +27 -0
- python_log_viewer-0.1.0/examples/django_example/README.md +18 -0
- python_log_viewer-0.1.0/examples/fastapi_example/README.md +18 -0
- python_log_viewer-0.1.0/examples/flask_example/README.md +18 -0
- python_log_viewer-0.1.0/pyproject.toml +48 -0
- python_log_viewer-0.1.0/src/python_log_viewer/__init__.py +10 -0
- python_log_viewer-0.1.0/src/python_log_viewer/_html.py +775 -0
- python_log_viewer-0.1.0/src/python_log_viewer/auth.py +39 -0
- python_log_viewer-0.1.0/src/python_log_viewer/contrib/__init__.py +1 -0
- python_log_viewer-0.1.0/src/python_log_viewer/contrib/django/__init__.py +4 -0
- python_log_viewer-0.1.0/src/python_log_viewer/contrib/django/apps.py +8 -0
- python_log_viewer-0.1.0/src/python_log_viewer/contrib/django/urls.py +19 -0
- python_log_viewer-0.1.0/src/python_log_viewer/contrib/django/views.py +163 -0
- python_log_viewer-0.1.0/src/python_log_viewer/contrib/fastapi.py +124 -0
- python_log_viewer-0.1.0/src/python_log_viewer/contrib/flask.py +124 -0
- python_log_viewer-0.1.0/src/python_log_viewer/core.py +165 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
*.egg-info/
|
|
4
|
+
dist/
|
|
5
|
+
build/
|
|
6
|
+
*.egg
|
|
7
|
+
.eggs/
|
|
8
|
+
*.whl
|
|
9
|
+
.venv/
|
|
10
|
+
venv/
|
|
11
|
+
.tox/
|
|
12
|
+
.mypy_cache/
|
|
13
|
+
.pytest_cache/
|
|
14
|
+
.venv/
|
|
15
|
+
venv/
|
|
16
|
+
.env
|
|
17
|
+
.env.local
|
|
18
|
+
.env.development.local
|
|
19
|
+
.env.test.local
|
|
20
|
+
.env.production.local
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python-log-viewer
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A beautiful, real-time log viewer with a web UI. Works with Django, Flask, and FastAPI.
|
|
5
|
+
Project-URL: Homepage, https://github.com/imsujan276/python-log-viewer
|
|
6
|
+
Project-URL: Repository, https://github.com/imsujan276/python-log-viewer
|
|
7
|
+
Project-URL: Issues, https://github.com/imsujan276/python-log-viewer/issues
|
|
8
|
+
Author-email: Sujan Gainju <sujangainju01@gmail.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
Keywords: django,fastapi,flask,log,logging,monitoring,viewer,web-ui
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Framework :: Django
|
|
13
|
+
Classifier: Framework :: FastAPI
|
|
14
|
+
Classifier: Framework :: Flask
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Classifier: Topic :: System :: Logging
|
|
26
|
+
Requires-Python: >=3.9
|
|
27
|
+
Provides-Extra: all
|
|
28
|
+
Requires-Dist: django>=3.2; extra == 'all'
|
|
29
|
+
Requires-Dist: fastapi>=0.68; extra == 'all'
|
|
30
|
+
Requires-Dist: flask>=2.0; extra == 'all'
|
|
31
|
+
Requires-Dist: uvicorn>=0.15; extra == 'all'
|
|
32
|
+
Provides-Extra: django
|
|
33
|
+
Requires-Dist: django>=3.2; extra == 'django'
|
|
34
|
+
Provides-Extra: fastapi
|
|
35
|
+
Requires-Dist: fastapi>=0.68; extra == 'fastapi'
|
|
36
|
+
Requires-Dist: uvicorn>=0.15; extra == 'fastapi'
|
|
37
|
+
Provides-Extra: flask
|
|
38
|
+
Requires-Dist: flask>=2.0; extra == 'flask'
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
|
|
41
|
+
# python-log-viewer
|
|
42
|
+
|
|
43
|
+
A beautiful, real-time log viewer with a dark-themed web UI. Browse, search, filter, clear, and delete log files — all from your browser.
|
|
44
|
+
|
|
45
|
+
Integrates seamlessly with **Django**, **Flask**, and **FastAPI**.
|
|
46
|
+
|
|
47
|
+

|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Features
|
|
52
|
+
|
|
53
|
+
- 📁 **File browser** — sidebar with folder tree, file sizes
|
|
54
|
+
- 🔍 **Search & filter** — full-text search, log-level filtering (DEBUG / INFO / WARNING / ERROR)
|
|
55
|
+
- 🎨 **Colour-coded** — log levels highlighted with subtle background colours
|
|
56
|
+
- 🔄 **Auto-refresh** — configurable live-tail (5s, 10s, 30s, 1m, or manual)
|
|
57
|
+
- 📜 **Line limits** — last 500 / 1000 / 2500 / 5000 / all entries
|
|
58
|
+
- 🗑️ **File actions** — clear (truncate) or delete log files with confirmation modals
|
|
59
|
+
- 🔒 **Basic Auth** — optional HTTP Basic Authentication
|
|
60
|
+
- 📱 **Responsive** — works on mobile with a slide-out sidebar
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Installation
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install python-log-viewer
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Framework extras
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install python-log-viewer[django] # Django integration
|
|
73
|
+
pip install python-log-viewer[flask] # Flask integration
|
|
74
|
+
pip install python-log-viewer[fastapi] # FastAPI integration
|
|
75
|
+
pip install python-log-viewer[all] # All frameworks
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Django Integration
|
|
81
|
+
|
|
82
|
+
### 1. Install
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
pip install python-log-viewer[django]
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 2. Add to `INSTALLED_APPS`
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
INSTALLED_APPS = [
|
|
92
|
+
# ...
|
|
93
|
+
"python_log_viewer.contrib.django",
|
|
94
|
+
]
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 3. Include URLs
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
# urls.py
|
|
101
|
+
from django.urls import path, include
|
|
102
|
+
|
|
103
|
+
urlpatterns = [
|
|
104
|
+
# ...
|
|
105
|
+
path("logs/", include("python_log_viewer.contrib.django.urls")),
|
|
106
|
+
]
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 4. Configure (optional)
|
|
110
|
+
|
|
111
|
+
Add any of these to your `settings.py`:
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
# Path to your log directory (default: BASE_DIR / "logs")
|
|
115
|
+
LOG_VIEWER_DIR = BASE_DIR / "logs"
|
|
116
|
+
|
|
117
|
+
# UI defaults
|
|
118
|
+
LOG_VIEWER_AUTO_REFRESH = True # enable auto-refresh
|
|
119
|
+
LOG_VIEWER_REFRESH_TIMER = 5000 # refresh interval in ms
|
|
120
|
+
LOG_VIEWER_AUTO_SCROLL = True # auto-scroll to bottom
|
|
121
|
+
LOG_VIEWER_COLORIZE = True # colour-coded log levels
|
|
122
|
+
|
|
123
|
+
# Authentication (optional — leave unset to disable)
|
|
124
|
+
LOG_VIEWER_USERNAME = "admin"
|
|
125
|
+
LOG_VIEWER_PASSWORD = "secret"
|
|
126
|
+
|
|
127
|
+
# Allow logged-in Django superusers to bypass Basic Auth (default: True)
|
|
128
|
+
LOG_VIEWER_SUPERUSER_ACCESS = True
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Then visit `http://localhost:8000/logs/` in your browser.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Flask Integration
|
|
136
|
+
|
|
137
|
+
### 1. Install
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
pip install python-log-viewer[flask]
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### 2. Register the blueprint
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from flask import Flask
|
|
147
|
+
from python_log_viewer.contrib.flask import create_log_viewer_blueprint
|
|
148
|
+
|
|
149
|
+
app = Flask(__name__)
|
|
150
|
+
|
|
151
|
+
app.register_blueprint(
|
|
152
|
+
create_log_viewer_blueprint(
|
|
153
|
+
log_dir="./logs",
|
|
154
|
+
url_prefix="/logs",
|
|
155
|
+
username="admin", # optional
|
|
156
|
+
password="secret", # optional
|
|
157
|
+
)
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
if __name__ == "__main__":
|
|
161
|
+
app.run(debug=True)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Then visit `http://localhost:5000/logs/` in your browser.
|
|
165
|
+
|
|
166
|
+
**Blueprint parameters:**
|
|
167
|
+
|
|
168
|
+
| Parameter | Default | Description |
|
|
169
|
+
|-----------|---------|-------------|
|
|
170
|
+
| `log_dir` | `"./logs"` | Path to log directory |
|
|
171
|
+
| `url_prefix` | `"/logs"` | URL prefix |
|
|
172
|
+
| `username` | `None` | Basic-Auth username |
|
|
173
|
+
| `password` | `None` | Basic-Auth password |
|
|
174
|
+
| `auto_refresh` | `True` | Enable auto-refresh |
|
|
175
|
+
| `refresh_timer` | `5000` | Refresh interval (ms) |
|
|
176
|
+
| `auto_scroll` | `True` | Auto-scroll to bottom |
|
|
177
|
+
| `colorize` | `True` | Colour-coded levels |
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## FastAPI Integration
|
|
182
|
+
|
|
183
|
+
### 1. Install
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
pip install python-log-viewer[fastapi]
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### 2. Include the router
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
from fastapi import FastAPI
|
|
193
|
+
from python_log_viewer.contrib.fastapi import create_log_viewer_router
|
|
194
|
+
|
|
195
|
+
app = FastAPI()
|
|
196
|
+
|
|
197
|
+
app.include_router(
|
|
198
|
+
create_log_viewer_router(
|
|
199
|
+
log_dir="./logs",
|
|
200
|
+
prefix="/logs",
|
|
201
|
+
username="admin", # optional
|
|
202
|
+
password="secret", # optional
|
|
203
|
+
)
|
|
204
|
+
)
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Then visit `http://localhost:8000/logs/` in your browser.
|
|
208
|
+
|
|
209
|
+
**Router parameters:**
|
|
210
|
+
|
|
211
|
+
| Parameter | Default | Description |
|
|
212
|
+
|-----------|---------|-------------|
|
|
213
|
+
| `log_dir` | `"./logs"` | Path to log directory |
|
|
214
|
+
| `prefix` | `"/logs"` | URL prefix |
|
|
215
|
+
| `username` | `None` | Basic-Auth username |
|
|
216
|
+
| `password` | `None` | Basic-Auth password |
|
|
217
|
+
| `auto_refresh` | `True` | Enable auto-refresh |
|
|
218
|
+
| `refresh_timer` | `5000` | Refresh interval (ms) |
|
|
219
|
+
| `auto_scroll` | `True` | Auto-scroll to bottom |
|
|
220
|
+
| `colorize` | `True` | Colour-coded levels |
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## Using the Core API Directly
|
|
225
|
+
|
|
226
|
+
The core classes have **zero dependencies** and can be used in any Python application:
|
|
227
|
+
|
|
228
|
+
```python
|
|
229
|
+
from python_log_viewer.core import LogDirectory, LogReader
|
|
230
|
+
|
|
231
|
+
# Point to your log directory
|
|
232
|
+
log_dir = LogDirectory("/var/log/myapp")
|
|
233
|
+
|
|
234
|
+
# List all files
|
|
235
|
+
for f in log_dir.list_files():
|
|
236
|
+
print(f"{f.name} {f.size} bytes modified={f.modified}")
|
|
237
|
+
|
|
238
|
+
# Read and filter log entries
|
|
239
|
+
reader = LogReader(log_dir)
|
|
240
|
+
result = reader.read(
|
|
241
|
+
file="app.log",
|
|
242
|
+
lines=100,
|
|
243
|
+
level="ERROR",
|
|
244
|
+
search="database",
|
|
245
|
+
)
|
|
246
|
+
print(f"Total matching entries: {result['total']}")
|
|
247
|
+
for line in result["lines"]:
|
|
248
|
+
print(line)
|
|
249
|
+
|
|
250
|
+
# File operations
|
|
251
|
+
log_dir.clear_file("app.log") # truncate to 0 bytes
|
|
252
|
+
log_dir.delete_file("old.log") # permanently remove
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## Environment Variables
|
|
258
|
+
|
|
259
|
+
Configuration can be set via environment variables (useful for Docker / CI):
|
|
260
|
+
|
|
261
|
+
| Variable | Description |
|
|
262
|
+
|----------|-------------|
|
|
263
|
+
| `LOG_VIEWER_USERNAME` | Basic-Auth username |
|
|
264
|
+
| `LOG_VIEWER_PASSWORD` | Basic-Auth password |
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## Development
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
# Clone
|
|
272
|
+
git clone https://github.com/imsujan276/python-log-viewer.git
|
|
273
|
+
cd python-log-viewer
|
|
274
|
+
|
|
275
|
+
# Install in editable mode
|
|
276
|
+
pip install -e ".[all]"
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## License
|
|
282
|
+
|
|
283
|
+
MIT
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# python-log-viewer
|
|
2
|
+
|
|
3
|
+
A beautiful, real-time log viewer with a dark-themed web UI. Browse, search, filter, clear, and delete log files — all from your browser.
|
|
4
|
+
|
|
5
|
+
Integrates seamlessly with **Django**, **Flask**, and **FastAPI**.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- 📁 **File browser** — sidebar with folder tree, file sizes
|
|
14
|
+
- 🔍 **Search & filter** — full-text search, log-level filtering (DEBUG / INFO / WARNING / ERROR)
|
|
15
|
+
- 🎨 **Colour-coded** — log levels highlighted with subtle background colours
|
|
16
|
+
- 🔄 **Auto-refresh** — configurable live-tail (5s, 10s, 30s, 1m, or manual)
|
|
17
|
+
- 📜 **Line limits** — last 500 / 1000 / 2500 / 5000 / all entries
|
|
18
|
+
- 🗑️ **File actions** — clear (truncate) or delete log files with confirmation modals
|
|
19
|
+
- 🔒 **Basic Auth** — optional HTTP Basic Authentication
|
|
20
|
+
- 📱 **Responsive** — works on mobile with a slide-out sidebar
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install python-log-viewer
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Framework extras
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install python-log-viewer[django] # Django integration
|
|
33
|
+
pip install python-log-viewer[flask] # Flask integration
|
|
34
|
+
pip install python-log-viewer[fastapi] # FastAPI integration
|
|
35
|
+
pip install python-log-viewer[all] # All frameworks
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Django Integration
|
|
41
|
+
|
|
42
|
+
### 1. Install
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install python-log-viewer[django]
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 2. Add to `INSTALLED_APPS`
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
INSTALLED_APPS = [
|
|
52
|
+
# ...
|
|
53
|
+
"python_log_viewer.contrib.django",
|
|
54
|
+
]
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 3. Include URLs
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
# urls.py
|
|
61
|
+
from django.urls import path, include
|
|
62
|
+
|
|
63
|
+
urlpatterns = [
|
|
64
|
+
# ...
|
|
65
|
+
path("logs/", include("python_log_viewer.contrib.django.urls")),
|
|
66
|
+
]
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 4. Configure (optional)
|
|
70
|
+
|
|
71
|
+
Add any of these to your `settings.py`:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
# Path to your log directory (default: BASE_DIR / "logs")
|
|
75
|
+
LOG_VIEWER_DIR = BASE_DIR / "logs"
|
|
76
|
+
|
|
77
|
+
# UI defaults
|
|
78
|
+
LOG_VIEWER_AUTO_REFRESH = True # enable auto-refresh
|
|
79
|
+
LOG_VIEWER_REFRESH_TIMER = 5000 # refresh interval in ms
|
|
80
|
+
LOG_VIEWER_AUTO_SCROLL = True # auto-scroll to bottom
|
|
81
|
+
LOG_VIEWER_COLORIZE = True # colour-coded log levels
|
|
82
|
+
|
|
83
|
+
# Authentication (optional — leave unset to disable)
|
|
84
|
+
LOG_VIEWER_USERNAME = "admin"
|
|
85
|
+
LOG_VIEWER_PASSWORD = "secret"
|
|
86
|
+
|
|
87
|
+
# Allow logged-in Django superusers to bypass Basic Auth (default: True)
|
|
88
|
+
LOG_VIEWER_SUPERUSER_ACCESS = True
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Then visit `http://localhost:8000/logs/` in your browser.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Flask Integration
|
|
96
|
+
|
|
97
|
+
### 1. Install
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
pip install python-log-viewer[flask]
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 2. Register the blueprint
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from flask import Flask
|
|
107
|
+
from python_log_viewer.contrib.flask import create_log_viewer_blueprint
|
|
108
|
+
|
|
109
|
+
app = Flask(__name__)
|
|
110
|
+
|
|
111
|
+
app.register_blueprint(
|
|
112
|
+
create_log_viewer_blueprint(
|
|
113
|
+
log_dir="./logs",
|
|
114
|
+
url_prefix="/logs",
|
|
115
|
+
username="admin", # optional
|
|
116
|
+
password="secret", # optional
|
|
117
|
+
)
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
if __name__ == "__main__":
|
|
121
|
+
app.run(debug=True)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Then visit `http://localhost:5000/logs/` in your browser.
|
|
125
|
+
|
|
126
|
+
**Blueprint parameters:**
|
|
127
|
+
|
|
128
|
+
| Parameter | Default | Description |
|
|
129
|
+
|-----------|---------|-------------|
|
|
130
|
+
| `log_dir` | `"./logs"` | Path to log directory |
|
|
131
|
+
| `url_prefix` | `"/logs"` | URL prefix |
|
|
132
|
+
| `username` | `None` | Basic-Auth username |
|
|
133
|
+
| `password` | `None` | Basic-Auth password |
|
|
134
|
+
| `auto_refresh` | `True` | Enable auto-refresh |
|
|
135
|
+
| `refresh_timer` | `5000` | Refresh interval (ms) |
|
|
136
|
+
| `auto_scroll` | `True` | Auto-scroll to bottom |
|
|
137
|
+
| `colorize` | `True` | Colour-coded levels |
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## FastAPI Integration
|
|
142
|
+
|
|
143
|
+
### 1. Install
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
pip install python-log-viewer[fastapi]
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### 2. Include the router
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
from fastapi import FastAPI
|
|
153
|
+
from python_log_viewer.contrib.fastapi import create_log_viewer_router
|
|
154
|
+
|
|
155
|
+
app = FastAPI()
|
|
156
|
+
|
|
157
|
+
app.include_router(
|
|
158
|
+
create_log_viewer_router(
|
|
159
|
+
log_dir="./logs",
|
|
160
|
+
prefix="/logs",
|
|
161
|
+
username="admin", # optional
|
|
162
|
+
password="secret", # optional
|
|
163
|
+
)
|
|
164
|
+
)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Then visit `http://localhost:8000/logs/` in your browser.
|
|
168
|
+
|
|
169
|
+
**Router parameters:**
|
|
170
|
+
|
|
171
|
+
| Parameter | Default | Description |
|
|
172
|
+
|-----------|---------|-------------|
|
|
173
|
+
| `log_dir` | `"./logs"` | Path to log directory |
|
|
174
|
+
| `prefix` | `"/logs"` | URL prefix |
|
|
175
|
+
| `username` | `None` | Basic-Auth username |
|
|
176
|
+
| `password` | `None` | Basic-Auth password |
|
|
177
|
+
| `auto_refresh` | `True` | Enable auto-refresh |
|
|
178
|
+
| `refresh_timer` | `5000` | Refresh interval (ms) |
|
|
179
|
+
| `auto_scroll` | `True` | Auto-scroll to bottom |
|
|
180
|
+
| `colorize` | `True` | Colour-coded levels |
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Using the Core API Directly
|
|
185
|
+
|
|
186
|
+
The core classes have **zero dependencies** and can be used in any Python application:
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
from python_log_viewer.core import LogDirectory, LogReader
|
|
190
|
+
|
|
191
|
+
# Point to your log directory
|
|
192
|
+
log_dir = LogDirectory("/var/log/myapp")
|
|
193
|
+
|
|
194
|
+
# List all files
|
|
195
|
+
for f in log_dir.list_files():
|
|
196
|
+
print(f"{f.name} {f.size} bytes modified={f.modified}")
|
|
197
|
+
|
|
198
|
+
# Read and filter log entries
|
|
199
|
+
reader = LogReader(log_dir)
|
|
200
|
+
result = reader.read(
|
|
201
|
+
file="app.log",
|
|
202
|
+
lines=100,
|
|
203
|
+
level="ERROR",
|
|
204
|
+
search="database",
|
|
205
|
+
)
|
|
206
|
+
print(f"Total matching entries: {result['total']}")
|
|
207
|
+
for line in result["lines"]:
|
|
208
|
+
print(line)
|
|
209
|
+
|
|
210
|
+
# File operations
|
|
211
|
+
log_dir.clear_file("app.log") # truncate to 0 bytes
|
|
212
|
+
log_dir.delete_file("old.log") # permanently remove
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## Environment Variables
|
|
218
|
+
|
|
219
|
+
Configuration can be set via environment variables (useful for Docker / CI):
|
|
220
|
+
|
|
221
|
+
| Variable | Description |
|
|
222
|
+
|----------|-------------|
|
|
223
|
+
| `LOG_VIEWER_USERNAME` | Basic-Auth username |
|
|
224
|
+
| `LOG_VIEWER_PASSWORD` | Basic-Auth password |
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Development
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
# Clone
|
|
232
|
+
git clone https://github.com/imsujan276/python-log-viewer.git
|
|
233
|
+
cd python-log-viewer
|
|
234
|
+
|
|
235
|
+
# Install in editable mode
|
|
236
|
+
pip install -e ".[all]"
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## License
|
|
242
|
+
|
|
243
|
+
MIT
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Examples
|
|
2
|
+
|
|
3
|
+
Sample applications demonstrating `python-log-viewer` integration with each supported framework.
|
|
4
|
+
|
|
5
|
+
All examples use the shared `sample_logs/` directory which contains realistic log files.
|
|
6
|
+
|
|
7
|
+
| Example | Framework | Port | Command |
|
|
8
|
+
|---------|-----------|------|---------|
|
|
9
|
+
| [django_example](./django_example/) | Django | 8000 | `python manage.py runserver 8000` |
|
|
10
|
+
| [flask_example](./flask_example/) | Flask | 5000 | `python app.py` |
|
|
11
|
+
| [fastapi_example](./fastapi_example/) | FastAPI | 8000 | `uvicorn app:app --reload` |
|
|
12
|
+
|
|
13
|
+
**Default credentials for all examples:** `admin` / `admin`
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# 1. Install the package in editable mode with all extras
|
|
19
|
+
cd /path/to/python-log-viewer
|
|
20
|
+
pip install -e ".[all]"
|
|
21
|
+
|
|
22
|
+
# 2. Pick an example and run it
|
|
23
|
+
cd examples/flask_example
|
|
24
|
+
python app.py
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then open the URL shown in the terminal.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Django Example
|
|
2
|
+
|
|
3
|
+
## Setup
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
# From the repository root
|
|
7
|
+
pip install -e ".[django]"
|
|
8
|
+
|
|
9
|
+
# Run the server
|
|
10
|
+
cd examples/django_example
|
|
11
|
+
python manage.py runserver 8000
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
Open http://localhost:8000/logs/ in your browser.
|
|
17
|
+
|
|
18
|
+
**Credentials:** `admin` / `admin`
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# FastAPI Example
|
|
2
|
+
|
|
3
|
+
## Setup
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
# From the repository root
|
|
7
|
+
pip install -e ".[fastapi]"
|
|
8
|
+
|
|
9
|
+
# Run the server
|
|
10
|
+
cd examples/fastapi_example
|
|
11
|
+
uvicorn app:app --host 0.0.0.0 --port 8000 --reload
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
Open http://localhost:8000/logs/ in your browser.
|
|
17
|
+
|
|
18
|
+
**Credentials:** `admin` / `admin`
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Flask Example
|
|
2
|
+
|
|
3
|
+
## Setup
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
# From the repository root
|
|
7
|
+
pip install -e ".[flask]"
|
|
8
|
+
|
|
9
|
+
# Run the server
|
|
10
|
+
cd examples/flask_example
|
|
11
|
+
python app.py
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
Open http://localhost:5000/logs/ in your browser.
|
|
17
|
+
|
|
18
|
+
**Credentials:** `admin` / `admin`
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "python-log-viewer"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A beautiful, real-time log viewer with a web UI. Works with Django, Flask, and FastAPI."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
license-files = []
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
authors = [{ name = "Sujan Gainju", email = "sujangainju01@gmail.com" }]
|
|
14
|
+
keywords = ["log", "viewer", "logging", "monitoring", "django", "flask", "fastapi", "web-ui"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Topic :: System :: Logging",
|
|
27
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
28
|
+
"Framework :: Django",
|
|
29
|
+
"Framework :: Flask",
|
|
30
|
+
"Framework :: FastAPI",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
django = ["django>=3.2"]
|
|
35
|
+
flask = ["flask>=2.0"]
|
|
36
|
+
fastapi = ["fastapi>=0.68", "uvicorn>=0.15"]
|
|
37
|
+
all = ["django>=3.2", "flask>=2.0", "fastapi>=0.68", "uvicorn>=0.15"]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://github.com/imsujan276/python-log-viewer"
|
|
41
|
+
Repository = "https://github.com/imsujan276/python-log-viewer"
|
|
42
|
+
Issues = "https://github.com/imsujan276/python-log-viewer/issues"
|
|
43
|
+
|
|
44
|
+
[tool.hatch.build.targets.wheel]
|
|
45
|
+
packages = ["src/python_log_viewer"]
|
|
46
|
+
|
|
47
|
+
[tool.hatch.build.targets.sdist]
|
|
48
|
+
include = ["src/python_log_viewer/", "README.md", "LICENSE"]
|