Refactor logging into helper function.