Skip to content

outputting the dump as html instead of just text opens up new possibilities #61

Description

@julian-goettingen

Hello,

I am using a custom library to log loads of information in error-scenarios in a long-running computation.
Today I discovered your library which is way more awesome than what I built.

However, there is one feature that I implemented in my code that I miss: The error-dumps are created as html.
This makes it possible to
(1) email them around, preserving colors
(2) print variables in a short form but keep the 'full' version as expandable on a click
(3) beatifully render objects that already define an html-representation (pandas dataframes)

Here is an example of what the script demo.py would output: (github doesnt let me upload as html but it is html)

demo_stack_dump.txt

If you are interested in having this feature I can code it up properly and we can maybe find a good way to expose it through the api in a backwards-compatible way.

Activity

  1. cknd commented on Nov 24, 2023

    @cknd
    Owner

    Hi, sorry for the long delay. That (html + clickable 'downloads' of the full variable content) was something I always wanted to add but never got around to. Sadly the logic is pretty intertwined with text formatting stuff, it might not be a pleasant project to add this

  2. julian-goettingen commented on Nov 27, 2023

    @julian-goettingen
    Author

    Thanks for the reply. The project I worked on in May is over now, and I have zero time for open-source-contributions right now so I have to retract my offer to help here. I do want to share what I did in the end, maybe it's useful to someone:

    I ended up using loguru for stack-printing, along with some custom logic to print the state of objects and local variables of a few frames. This produces a pure text output except in a few places where I actually wanted html (mostly the expandable sections and pandas). Instead of putting the html directly in the text, I put only an identifier in the text, so the text without any html-elements could be converted to html with ansi2html. After that, the identifiers are replaced by html again.

    I can't share the code as it was closed source (and it is messy anyways), but I wanted to drop the idea that helped me do it with ansi2html that I also used to hack it in here to make the demo_stack_dump linked above:

    1. Keep the text-producing-logic
    2. When you want to turn something into html, do it, but only emit an identifier to be included in the text
    3. Convert the whole text to html with tools that exist
    4. Put the html back in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions