Factorize some code in time logging