The things I’m thinking off are way more cowboy than what you’re doing @aberquand! I think @sgugger’s solution is the cleanest.
You could redirect all the logs to a text file and then filter them out, but your approach here sounds better.