Fix the mangled text when logging from multiple threads.