Rewrite log thingy so it uses less of a global variable mess.