It is not directly possible to toggle handler tracking at runtime because BOOST_ASIO_ENABLE_HANDLER_TRACKING
is a preprocessor macro used to compile different code paths depending on its value. The desired behavior can be achieved by implementing custom runtime dispatch. Injection can be done via the Custom Tracking mechanism. The same mechanism can also be used to redirect output to a different destination, as well as to perform any other customization supported by the provided interface.