Implement thread-safe debug output, use it