Refactor log.c a bit.