Make debug header thread safe and make it print only on DEBUG.