[Reviewer: Andy] Rework the fake logger used in UTs

Most of this is self-explanatory, but I saw a lot of memory corruption when running UTs (particularly the 'this' pointer of my HSSConnection being set to '2'). I don't believe this was caused by these changes - I could reproduce them on other branches - and I suspect I saw them because this laptop is slower than my ordinary PC and race conditions happen differently. I think this is the same issue as https://github.com/Metaswitch/sprout/issues/606 - it really annoyed me, so I resolved it by putting locks in Log::write and Log::set_logger to avoid threads trampling on each other.

Should be safe, performance-wise, for production - log levels are typically low there, and I made sure that checking the log level (and doing nothing if it's too high) comes before trying to acquire the lock.
There's a threadsafe initializer value provided by pthreads for just this use, google for `PTHREAD_MUTEX_INITIALIZER` for details.