Initialise and clean up Mapserver debug on a per thread basis

The `msDebug()` function is thread aware and needs to be properly
initialised and cleaned up for each thread.