Refactor time logging