Rewrite global logging code for thread safety, and add documentation to public functions and struct

7 jobs for logging_thread_safety in 1 minute and 34 seconds (queued for 1 second)