-
Notifications
You must be signed in to change notification settings - Fork 673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possibilities to add visual images to python log #1135
Comments
It all depends on how you intend to view your logs and images. Logs are just text. If you wish to embed images, you need to define an encoding format that will be recognized by the application used to read your logs. For example, if your logs are read in a terminal, it's unlikely that you'll be able to display any images at all. |
Thank you for the explanation! I figured out a way to encode images into base64 strings and save them to a plain HTML file. But this thing won't work with the terminal for sure. The code is posted here for someone who has the same need and close this issue now. logging_path = 'test.html'
with open(logging_path, "a") as f:
f.write(f"<h1>Title </h1>")
f.write("<h3>Image Input</h3>")
f.write(f'<img src="data:image/png;base64,{base64_image}">')
f.write("<h3>JSON format output: </h3>")
f.write(f"<pre>{captioning}</pre>")
f.write(
'<hr style="height:2px;border-width:0;color:gray;background-color:gray">'
) |
Hi,
I would like to add some debugging images (png format) to the logging for better visualization. Seems like it's hard to find a library that natively supports adding images to logging.
I found some code elsewhere (below) but it's not working well cosmetically. Do you have any suggestions using loguru to save images?
Thank you!
And the result HTML looks like this:
The text was updated successfully, but these errors were encountered: