Skip to content

visual-logging 2.0: modern packaging/CI, styled HTML pages, Jupyter support, max_size#19

Merged
dchaplinsky merged 5 commits into
masterfrom
claude/modernize-visual-logging
Jul 19, 2026
Merged

visual-logging 2.0: modern packaging/CI, styled HTML pages, Jupyter support, max_size#19
dchaplinsky merged 5 commits into
masterfrom
claude/modernize-visual-logging

Conversation

@dchaplinsky

@dchaplinsky dchaplinsky commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Revives the project as a proper 2.0. Old API keeps working; everything new composes the stdlib logging way.

Packaging

  • Replace setup.py / devrequirements.txt with pyproject.toml: version 2.0, requires-python >= 3.9, PyPI classifiers, a test extra, py.typed marker
  • Deleting devrequirements.txt (Pillow 2.5.1, matplotlib 1.4.1) should clear all open Dependabot alerts and supersedes Bump pillow from 2.5.1 to 9.3.0 #18

CI / releasing

  • Remove the dead Travis + Coveralls setup (the Travis config built OpenCV 2.4.9 from source and contained a stale Slack webhook token)
  • tests.yml: GitHub Actions matrix for Python 3.9–3.13
  • publish.yml: builds and publishes to PyPI via trusted publishing on v* tags (one-time setup needed on PyPI: project → Publishing → add GitHub publisher for this repo, workflow publish.yml, environment pypi)

New features

  • HTMLFileHandler + VisualFormatter — a logging.FileHandler/logging.Formatter pair producing a self-contained styled page: level-colored record cards, timestamps, logger names, dark-mode aware CSS; plain log messages are escaped and mix in; logger.exception(...) records include the traceback; records flush as emitted so the page can be watched mid-run. A bare FileHandler still produces 1.x-style fragments.
  • max_size=(width, height) on VisualRecord downscales oversized images (aspect ratio preserved) before embedding — OpenCV/PIL via resize, matplotlib by lowering savefig dpi. Implements the idea from image resize option added #10.
  • Jupyter support: VisualRecord displays inline via _repr_html_.
  • render_numpy fallback: numpy arrays render through PIL when OpenCV isn't installed.
  • Embedded images get loading="lazy", so huge logs open fast.

Code

  • f-strings, type hints, docstrings; shared _fit_scale() for the downscale policy
  • matplotlib renderer gated on matplotlib instead of the deprecated pylab module; render_pylab kept as an alias
  • The Python 3 base64 fix that fixing problem of not seeing images on python3 #5 addressed is already in master, so that PR can be closed

Tests

  • Ported from nose to pytest, 20 tests: renderers, max_size for all three backends, lazy loading, _repr_html_, page structure, escaping, tracebacks, double-close; the no-renderers corner case uses mock.patch.dict(sys.modules, ...) instead of dummy modules
  • Verified locally: suite green on 3.11, demo.py produces a styled log with 7 records / 10 images

Docs

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ha16zNy2fDMdrZBMQGgpBt

dchaplinsky and others added 4 commits July 19, 2026 09:27
…x_size option

- Replace setup.py/devrequirements.txt with pyproject.toml (version 2.0)
- Replace dead Travis CI + coveralls setup with a GitHub Actions test
  matrix for Python 3.9-3.13
- Add max_size option to VisualRecord to downscale embedded images
  (inspired by PR #10)
- Gate the matplotlib renderer on matplotlib itself instead of the
  deprecated pylab module (render_pylab kept as an alias)
- Move tests to tests/, port them from nose to pytest and make the
  no-renderers corner case run in-process
- Refresh README and demo.py, document logging.shutdown() (issue #8)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ha16zNy2fDMdrZBMQGgpBt
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ha16zNy2fDMdrZBMQGgpBt
- Share the shrink-only scale policy between renderers via _fit_scale
  instead of two divergent per-renderer formulations
- Downscale PIL images with resize() instead of a full-resolution copy()
  followed by in-place thumbnail()
- Replace the dummy-module directory and hand-rolled sys.modules
  save/restore in the corner-case test with mock.patch.dict
- Document that max_size does not apply to matplotlib figures

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ha16zNy2fDMdrZBMQGgpBt
…PI 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
@dchaplinsky dchaplinsky changed the title Modernize for Python 3.9+: pyproject packaging, GitHub Actions CI, max_size option visual-logging 2.0: modern packaging/CI, styled HTML pages, Jupyter support, max_size Jul 19, 2026
…rity

- VisualFormatter now owns STYLE, the stylesheet for the cards it emits;
  HTMLFileHandler embeds its formatter's STYLE and keeps only page framing
- Level CSS class is derived from record.levelno severity buckets, so
  custom levels from logging.addLevelName inherit the nearest standard
  color instead of rendering unstyled
- Deduplicate the exc_info/stack_info traceback template
- Drop the dead .record hr CSS rule

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ha16zNy2fDMdrZBMQGgpBt
@dchaplinsky
dchaplinsky merged commit 4092ba6 into master Jul 19, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant