Refactor logging a bit.