Restructuring/thread local log context

Implementation of thread-local log context and corresponding cleanups.