pawamoy/markdown-exec

[Feature] Output logging in rendered output

eddiebergman opened this issue · 2 comments

Is your feature request related to a problem? Please describe.
I am using markdown_exec to have examples which are also run and show their output. Part of this would be nice to display the logging output too.

Describe the solution you'd like
An annotation similar to exec=True except you specify the logging level, i.e. logs=INFO.

Describe alternatives you've considered
I previously injected hidden code into the code blocks that would take the buffer that you overwrite the print builtin with and set this to the outstream of rich.print. I could do something similar for logging but I would prefer not to rely on private functionality.

I recently did so with sessions, injecting in session["__name__"] = "__main__" to run the example script's __main__ block, as well as try solve issues to pickling that occur when using markdown exec but to no avail. A recent PR changed the name of the global variable so it was a good lesson not to rely on the private functionality.

Additional context
The logging from the running examples actually gets streamed to the session running mkdocs --serve which pollutes the build output. It would be good to redirect this anywho.

Hey @eddiebergman, thanks for the feature request.

How do your scripts/examples configure logging? I'm not against a logs option which defaults to None and that, when provided a log level, redirect all logs to our buffer, keeping only the ones with a level greater or equal the specified one.