You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Round out 2.0: HTML page handler, Jupyter support, numpy renderer, PyPI publishing
- New HTMLFileHandler + VisualFormatter: self-contained styled html pages
with level-colored record cards, timestamps, logger names, escaped
plain-text records and tracebacks; flushed per record so the page can
be watched mid-run. Both are plain logging.FileHandler/Formatter
subclasses and compose the stdlib way; 1.x usage with a bare
FileHandler keeps working
- VisualRecord displays inline in Jupyter via _repr_html_
- max_size now applies to matplotlib figures too, by lowering savefig dpi
- New render_numpy fallback: numpy arrays render via PIL when OpenCV is
not installed
- Embedded images get loading="lazy" so large logs open fast
- Type hints throughout and a py.typed marker
- publish.yml: build + publish to PyPI via trusted publishing on v* tags
- demo.py showcases the new handler; README rewritten accordingly
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ha16zNy2fDMdrZBMQGgpBt
Copy file name to clipboardExpand all lines: README.md
+23-9Lines changed: 23 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,20 +16,19 @@ You can read about it in detail in a great blog post [visual-logging, my new fav
16
16
pip install visual-logging
17
17
```
18
18
19
-
No extra dependencies — whichever of OpenCV, PIL/Pillow and matplotlib you already have installed are picked up automatically. Requires Python 3.9+.
19
+
No extra dependencies — whichever of OpenCV, PIL/Pillow and matplotlib you already have installed are picked up automatically (numpy arrays render through PIL when OpenCV isn't around). Requires Python 3.9+.
20
20
21
21
## Usage example (see demo.py)
22
22
23
23
```python
24
24
import logging
25
-
from logging import FileHandler
26
-
from vlogging import VisualRecord
25
+
from vlogging import HTMLFileHandler, VisualRecord
27
26
28
27
import cv2 # or PIL.Image, or matplotlib — whatever you use
"Hello from all", [cv_image, pil_image, mpl_figure],
43
42
fmt="png", max_size=(320, 240)))
44
43
44
+
# Ordinary log calls work too, and land in the same page:
45
+
logger.info("Processed frame %d", 42)
46
+
45
47
logging.shutdown() # flushes and closes the html file
46
48
```
47
49
48
-
Open `test.html` in a browser and enjoy. A sample of generated html is available [here](http://dchaplinsky.github.io/visual-logging/).
50
+
Open `test.html` in a browser and enjoy: `HTMLFileHandler` writes a styled, self-contained page — records are color-coded by log level with timestamps and logger names, plain messages are escaped, and exceptions logged with `logger.exception(...)` include their traceback. Records are flushed as they happen, so you can watch the page mid-run.
51
+
52
+
Everything composes the stdlib way: `HTMLFileHandler` is a `logging.FileHandler` that installs a `VisualFormatter` (a `logging.Formatter`) by default — use either piece on its own if you prefer. Passing a `VisualRecord` to a plain `FileHandler` still produces bare html fragments, exactly as in 1.x.
53
+
54
+
In **Jupyter**, a `VisualRecord` displays itself inline — no logging setup needed:
@@ -55,12 +65,16 @@ Open `test.html` in a browser and enjoy. A sample of generated html is available
55
65
|`imgs`| A single image or a list of images: OpenCV/numpy arrays, PIL images and matplotlib figures in any combination |
56
66
|`footnotes`| Optional text rendered as `<pre>` under the images |
57
67
|`fmt`| Image format to embed: `png` (default), `jpeg`, `webp` — anything your imaging library can encode |
58
-
|`max_size`| Optional `(width, height)` tuple: OpenCV and PIL images bigger than that are downscaled proportionally before embedding, to keep log files readable and small (matplotlib figures are embedded as rendered)|
68
+
|`max_size`| Optional `(width, height)` tuple: images bigger than that are downscaled proportionally before embedding (matplotlib figures by lowering the render dpi), to keep log files readable and small |
59
69
60
70
## Changelog
61
71
62
72
**2.0**
63
-
- Modern packaging (`pyproject.toml`), Python 3.9+ only
64
-
- New `max_size` option to downscale embedded images
73
+
- Modern packaging (`pyproject.toml`), Python 3.9+ only, `py.typed` type hints
74
+
- New `HTMLFileHandler` + `VisualFormatter`: styled, self-contained html pages with level colors, timestamps, escaped plain-text records and tracebacks
75
+
- New `max_size` option to downscale embedded images (all renderers)
76
+
-`VisualRecord` displays inline in Jupyter notebooks
77
+
- numpy arrays render via PIL when OpenCV is not installed
78
+
- Embedded images use `loading="lazy"`, so huge logs open fast
65
79
- matplotlib support no longer relies on the deprecated `pylab` module
66
-
- Tests run on GitHub Actions against Python 3.9–3.13
80
+
- Tests run on GitHub Actions against Python 3.9–3.13; releases publish to PyPI from tags via trusted publishing
0 commit comments