8

I'm writing a scientific program that has some intermediate results (plots and images) that I'd like to log (additional to the usual text messages).

I like python's logging interface a lot, so I'm wondering if there is a possibility to use it to create log files that include images.

The first idea that came to my mind was creating a log file as a SVG, so the log text is machine readable and the images can be included easily.

Is there a better approach to make this possible?

Torxed
  • 22,866
  • 14
  • 82
  • 131

1 Answers1

0

You could use SVG, but I'm not sure how compact the SVG would be since it would probably (in general) store the bitmap rather than vector information. An alternative would be to base64-encode the image and store it using a structured format, as documented here - the linked example uses JSON, which might be handy to e.g. store metadata about the image, but you could use a simpler scheme if all you're storing is the image and the format is always the same.

Vinay Sajip
  • 95,872
  • 14
  • 179
  • 191