Deglobalization: optional logging and clearing
Logging to help debug issues caused by deglobalization.
Clearing globals is now off by default so no further crashes.
This avoids the crash in #2313 (closed) but doesn't fix the underlaying bug, just hides it - the proper fix is !725 (closed). This MR can help understand how the globals are used.